logo
Tags down

shadow

how to upload multiple files using a single upload control in a MVC application


By : AcToR
Date : October 18 2020, 06:10 AM
To fix the issue you can do You can get multiple files using Request.Files as HttpFileCollectionBase and through iteration you can upload multiple files.
code :
[HttpPost]
        public ActionResult Index(HttpPostedFileBase FileUpload1)
        {
            if (FileUpload1.ContentLength > 0)
            {
                HttpFileCollectionBase files = Request.Files;
                DataTable dt = new DataTable { Columns = { new DataColumn("Path") } };
                for (int i = 0; i < files.Count; i++)
                {
                    HttpPostedFileBase file = files[i];
                    string path = Server.MapPath("~") + "\\Images\\" + file.FileName;
                    dt.Rows.Add(file.FileName);
                    file.SaveAs(path);
                }
                ViewData.Model = dt.AsEnumerable();
            }
            return View();
        }


Share : facebook icon twitter icon

Unable to upload files through File Upload control


By : Allcats
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Add Network Service (in security) and give all full control for the folder to which you are uploading the file. if still it doesn't work then add Everyone and give full control.

How to upload files using Kendo UI File Upload Control?


By : John Black
Date : March 29 2020, 07:55 AM
hope this fix your issue I have a simple HTML page and i would like to upload a file from client machine to server side, here i am trying to upload a file using Kendo UI contorl, but it doesn't work fine, i have given my code details below. , Try this example to illustrate your problem
code :
<html>
<head>
    <title></title>
    <link href="styles/kendo.common.min.css" rel="stylesheet" />
    <link href="styles/kendo.default.min.css" rel="stylesheet" />
    <script src="js/jquery.min.js"></script>
    <script src="js/kendo.all.min.js"></script>
</head>
<body>

        <div id="example" class="k-content">
            <div class="configuration">
                <span class="infoHead">Information</span>
                <p>
                    The Upload can be used as a drop-in replacement
                    for file input elements.
                </p>
                <p>
                    This "synchronous" mode does not require
                    special handling on the server.
                </p>
            </div>
            <form method="post" action="submit" style="width:45%">
                <div class="demo-section">
                    <input name="files" id="files" type="file" />
                    <p>
                        <input type="submit" value="Submit" class="k-button" />
                    </p>
                </div>
            </form>
            <script>
                $(document).ready(function() {
                    $("#files").kendoUpload();
                });
            </script>
        </div>


</body>
</html>

How to use two multiple file upload control files in a single button click


By : user2368662
Date : March 29 2020, 07:55 AM
I hope this helps you . Don't use Request.Files. It contains all files from FileUpload1 and FileUpload2. Use FileUpload2.PostedFiles instead.
Here's an example usage
code :
protected void uploadFiles_Click(object sender, EventArgs e)
    {
        if (FileUpload2.HasFiles)
        {
            foreach (HttpPostedFile uploadedFile in FileUpload2.PostedFiles)
            {
                uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/MyPath/"),
                uploadedFile.FileName));
                listofuploadedfiles.Text += String.Format("{0}<br />", uploadedFile.FileName);
            }
        }
    }

Restrict file upload control to upload only certion type of files in c #


By : Liam Pino
Date : March 29 2020, 07:55 AM
To fix this issue In web application how to restrict the uploaded file types when opening file upload dialog. If you are using ASP.NET & c# , Just validate the file extension as i did for excel file

Django Admin - Upload multiple images to multiple model objects in a single upload


By : Mihail Potinteu
Date : October 10 2020, 11:00 PM
I wish did fix the issue. Update thousands of records at once is challenging as default.
One issue is the performance on the database side. the best I could come up is using update and overwriting some methods. assume you already have your images in some directory.
code :
from django.db.models import fields
from django.db.models import F
from django.db.models.expressions import Value , CombinedExpression
from django.db.models import QuerySet

class TextValue(Value):
    def as_sql(self, compiler, connection):
        connection.ops.check_expression_support(self)
        return '%s', [self.value]

class Expr(F):
    ADD = '||'  # standard concat row value + value in PostgreSQL

    #overwrite method to support text
    def _combine(self, other, connector, reversed):
        if not hasattr(other, 'resolve_expression'):
            other = TextValue(other, output_field=fields.CharField())

        return CombinedExpression(self, connector, other)


class Entry(models.Model):
    name = models.CharField(unique=True, max_length=200, db_index=True)
    image = models.ImageField(upload_to= 'media/' , null=True, blank=True , default='default.png')
entries= Entry.objects.all() 
entries.update(**{'image': Expr('name') + '.png'})
{'sql': 'UPDATE "entry" SET "image" = ("entry"."name" || \'.png\')', 'time': '0.024'}]
from django.contrib import  admin
from django import forms


class EntryForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(EntryForm, self).__init__(*args, **kwargs)
        self.fields['image'].widget.attrs.update(
            {'multiple': True, 'accept': 'image/jpg,image/png,image/gif', })


class EntryAdmin(admin.ModelAdmin):
    form = EntryForm

    def save_model(self, request, obj, form, change):
        files = request.FILES.getlist('image')

        # if image exist
        if files:
            for image_field in files:
                try:
                    instance = Entry.objects.get(name=image_field.name[:-4])
                    instance.image = image_field
                    instance.save()
                except Entry.DoesNotExist:
                    pass
        else:
            return super().save_model(request, obj, form, change)



admin.site.register(Entry , EntryAdmin)
Related Posts Related Posts :
  • Remove duplicates from comma separated list
  • Use a String variable as argument from if sentence
  • unity how to avoid scaling heritage when parenting?
  • Is there a way to do nested model binding with the [FromBody] attribute?
  • How to insert dynamic query into table using c#
  • Why Unit Testing Assert.AreEqual() method does NOT pick up my own Equals() method in the customized class
  • Unity Error: Feature 'out variable declaration'
  • What happens if my C# switch expression is non-exhaustive?
  • How Can I Select an ItemTemplate Based on a Value?
  • EF Class table name and column have same name
  • Substring issues - input string was not in a correct format
  • C# Asynchronously read data from a redirected StandardOutput
  • The code after await operation is not executing
  • Image FILL logic such as "Stretch.Uniform" of WPF
  • Why am I allowed to declare a variable with the same name?
  • Simplest way to display colored 3D boxes in winforms
  • Conventions on having both an API and MVC project in .NET Core solution
  • File upload .NET Core 'IFormFile' does not contain a definition for 'CopyToAsync' and no extension method
  • Deserialize only valid objects by ignoring errors
  • How to write into text file what is ordered by years
  • Remove this 'return' statement or make it conditional
  • Cannot implicitly convert type "System.DateTime" to "LearnScan.LearnUser.NullableDateTime"
  • Why does DateTime.UtcNow.Subtract give me a massive number sometimes?
  • How to restart CancellationTokenSource after make it cancel in c#?
  • Same data is fetched from the database every time
  • JSON Deserialize is not working with List object
  • Convert Visual Studio 2017 C# solution / project for use with Mono on Linux?
  • Sort list by multiple variables
  • How valid is it to use `Result` inside `Task.Run`
  • how to put a variable in the image source in C# like we do in php
  • How to display an image stored in database as bytes into a View?
  • MVC issue for accessing the data from database:The parameters dictionary contains a null entry for parameter 'id' of non
  • Is there a method to group 4 controls into an UserControl or template and use it in parent UserControl and bind them wit
  • Xamarin Forms : can Prism and ReactiveUI be used in the same project ? If so, is it a good idea?
  • How can I paste the "plain" text of a string to int? C#
  • How to determine which table a column belongs to in an SQL Statement given metadata information and parse tree from SQL
  • How to fix The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. The statemen
  • AutoHotkey: Remap shortcut for MS Visio to align manually selected objects to the top (as if pressing: "AlignTop&qu
  • Can .csproj Switch native code by platform?
  • How to use HttpClientFactory with AutoRest generated client
  • Parsing a phrase with Sprache(Words seperated by spaces)
  • called from Blazor client HttpClient.GetJsonAsync returns (with data), but then times out
  • Two processors can't log the information at the same time by using NLog
  • C# streamreader read data multiple times
  • Healthbar not decreasing when player is collided with the laser
  • Why are .cshtml changes are not reflected locally until app pool recycle? Why did building my project in Visual Studio s
  • How to make a specific order for calling methods?
  • Why OnCollisionEnter2D / OnTriggerEnter2D don't work?
  • how to use async and await so that it will create a different task or each request
  • Should unit tests tests the functionality of a method?
  • ILGenerator emiting call GetHashCode on int
  • How to register singleton factory resolving scoped objects in ASP.NET Core?
  • How to use C# 6.0 or 7.0 in an old ASP.NET Website (not Website Project)
  • How to ensure that the WCF service will not communicate to the database in parallel
  • Removing items from LinkedList<>
  • Can you instantiate another class within the constructor?
  • Best way to instantiate a class with a private object that needs instantiating as well
  • C# Memory Issues
  • Should a input object be cloned if it is the return value?
  • How to pass c# decimal to sql decimal(4,2)
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk