Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Muliple File Uploader in asp.net

Posted on 2009-04-21
28
Medium Priority
?
1,636 Views
Last Modified: 2012-05-06
http://ajaxuploader.com/
This uploader is just like how the gmail files are uploading,
i need exactly uploading multiples files like that.,
0
Comment
Question by:Rajeshk_cgm
  • 14
  • 14
28 Comments
 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24192514
but i need to add the images in different folder, here in the above examples they had given all those in dll., and mentioned the single folder name uploads.,
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24192618
i need to save the images in different folder
for example
if am selecting a car model Audi from a dropdownlist means, it should save the images in that corresponding Audi folder, if the Car Model is Honda., it should save the images under the Honda Folder


Please any one help me.... :-(
0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24192804
This should server your purpose, you can modify the code to get the upload path as per your liking:
http://dotnetslackers.com/articles/aspnet/Upload_multiple_files_using_the_HtmlInputFile_control.aspx
 
0
 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24194109
its working fine with local server, but in Server [FTP] uploading is done without showing any error but its images are not saved under the folder., is there is any issues using the Fileupload dll [its a Free version only right..?] we can use it ..?

http://weblogs.asp.net/jstengel/archive/2008/04/25/flash-file-upload-server-control.aspx
0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24194282
Yes you can use it, its free. Check if you have proper access setup for writing a file to the remote server.
0
 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24194524
i have checked, we have right option for that folder., am sure about that., but still images are not saving inside that folder.,
0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24194857
Unless there is an error, i can really not suggest a solution. Since you do not get an error, i though may be its a rights issue. Paste your code here, I will have a look. Also, did you download the source code for the control from the site. It would help to see what that code is doing.
0
 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24201647
Inline Coding...

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="RD" Namespace="FlashUpload" Assembly="FlashUpload" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
     <style type="text/css">
        body {font-family: Arial;margin:0; padding:0;}
        h1 {padding:20px; text-align:center; border-bottom:2px dotted #333; background-color:#ccc;}
        fieldset {margin:20px; padding:10px;}
        legend {font-weight:bold; color:Blue;}
        h3 {margin: 10px 10px 0 10px; clear:both; border-bottom: 1px dotted #ccc;}
        ol {font-size:80%;}
        p {margin-left:20px; }
        pre {padding:5px; background-color:#ccc;}
        table {border-collapse:collapse;}
        td {font-size:80%; padding:5px; border:1px solid #000;}
        tr.HeaderRow {font-weight:bold; background-color:#ccc;}
        td.Property {color:Blue; font-weight:bold;}
        td.Description {font-style:italic;}
    </style>
    <link href="FlashUpload.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <RD:FlashUpload runat="server" ID="fileUpload" />
    </div>
    </form>
</body>
</html>

 
Code Behind..
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
In page load i have mentioned the folder name, which having Access
<%@ Register TagPrefix="RD" Namespace="FlashUpload" Assembly="FlashUpload" %>
protected void Page_Load(object sender, EventArgs e)
{
this.fileUpload.SaveToPath = "~/Uploads/";
}




Upload handler ashx file..

<%@ WebHandler Language="VB" Class="MyHandler" %>
''' <summary>
''' This handler takes a posted file and saves it to the disk.
''' </summary>
''' <remarks></remarks>
Public Class MyHandler
Implements IHttpHandler


Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Try
'System.Threading.Thread.Sleep(5000) 'Slow down for testing only!
Dim myFile As HttpPostedFile = context.Request.Files(0)
Dim RootPath As String = context.Server.UrlDecode(context.Request.QueryString("Path"))
If System.IO.File.Exists(context.Server.MapPath(RootPath & myFile.FileName)) Then
If CBool(context.Request.QueryString("Overwrite")) Then
myFile.SaveAs(context.Server.MapPath(RootPath & myFile.FileName))
Else
context.Response.Write("500") 'File already exists and will not be overwritten.
End If
Else : myFile.SaveAs(context.Server.MapPath(RootPath & myFile.FileName))
End If
context.Response.Write("200") 'IMPORTANT! Respond Ok.
Catch ex As Exception
context.Response.Write("500") 'IMPORTANT! Respond not Ok.
End Try
End Sub


Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
Get
Return False
End Get
End Property


End Class
 

Web.config..

<httpRuntime maxRequestLength="2000000"/>

I have the Fileupload dll file in my Bin Folder too.,
Can you say whats the problem,



<?XML:NAMESPACE PREFIX = RD />




0
 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24201702
And More over i have tried the example in the follwing link which you had given

http://www.codeproject.com/KB/aspnet/FlashUpload.aspx

but here also am getting error. i have attached the error snapshot.,

please have a look and give me yr suggestion
FileUploadError.bmp
0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24202994
Rajeshk_cgm: Debug the code for flash upload at the below link line by line and find put exactly where the error is coming, i/o error points towards improper permissioning: http://www.codeproject.com/KB/aspnet/FlashUpload.aspx
 
0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24203043
The IIS/ ASPNET Machine account needs to have all the modify/write grants on the folder where you are trying to upload the file. Because its the IIs/ASPNET account thats works on your request.
Refer to these links:
http://www.kodyaz.com/articles/asp-net-file-upload-security-permissions.aspx
http://bytes.com/groups/net-asp/578390-file-uploading-permission
http://msdn.microsoft.com/en-us/library/dwc1xthy.aspx
 
0
 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24203101
Yes, Actually they had given two Folder[with authentication and without authentication] i have tested  the form with authentication, its working fine without any error in local, but the same project when i update with server., it showing error 2038 and also showing file not found 404 error.,

Actually in the below code they had given  Uploadpage="Upload2.axd" [class file is named as upload2.cs), and they mentioned the httphandler in web config as
 
   <remove verb="POST,GET" path="Upload.axd"/>
      <add verb="POST,GET" path="Upload.axd" type="Upload"/>
      <remove verb="POST,GET" path="Upload2.axd"/>
      <add verb="POST,GET" path="Upload2.axd" type="Upload"/>


 <FlashUpload:FlashUpload ID="flashUpload" runat="server"
            UploadPage="Upload2.axd" OnUploadComplete="UploadComplete()"
            FileTypeDescription="Images" FileTypes="*.gif; *.png; *.jpg; *.jpeg"
            UploadFileSizeLimit="1800000" TotalUploadSizeLimit="2097152" />

 i  dont know where i did mistake......
0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24203134
Since the same code is working fine in local, the problem is definitley with permissioning on the server.
Make sure all the multiple server upload paths have the proper permissioning setup for IIS_USR/ASPNET user account.
0
 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24203254
oh.. really thanks a lot, now its working fine with server.. too.. thanks a lot.,

Can you say how to change the folder name in runtime., to save the images

Here they had given the static folder name as upload in Upload2.cs and upload.cs..

I need to save the images accroding to the dropdownlist selection value of folder name

is it possible to change the folder name dynamically..?

0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24203322
You can keep the folder names same as the selection values from the drop down menu.
Then based on the selection by user, pass the slected value as a folder name to the upload path in the files Upload2.cs and upload.cs.
0
 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24203427
ya, thanks, i have passed the folder name using Session.,

Can you suggest me one more thing, to avoiding file size limitation. what i should do., its not accepting to upload 1 MB itself, only few image [2-4 images]

what shall i do to upload more images[ upto 20 and size of nearly 25 MB]
0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24203496
Glad you asked that.I had faced a similar issue some years back. Good i documented the solution. There are two ways to do this:
1. Increase the following in webconfig:
<httpRuntime maxRequestLength="1550000"/>
OR
 2. You need to make some simple settings on the IIS as showb in the attachment.
This should solve your problem.

Ø	Settings to be done for increasing the file transmission size through ASP
 
Pure ASP Upload supports uploading large files on the Windows 2003 server. However:
 
IIS6.0 prevent the upload of files more than +200Kb. So you need to make some changes in the default IIS settings first.
 
Background
For IIS6.0 users, the AspMaxRequestEntityAllowed property specifies the maximum number of bytes allowed in the entity body of an ASP request. If a Content-Length header is present and specifies an amount of data greater than the value of AspMaxRequestEntityAllowed, IIS returns a 403 error response.
 
This property is related in function to MaxRequestEntityAllowed, but is specific to ASP request. Whereas you might set the MaxRequestEntityAllowed property to 1 MB at the general World Wide Web Publishing Service (WWW Service) level, you may choose to set AspMaxRequestEntityAllowed to a lower value, if you know that your specific ASP applications handle a smaller amount of data.
 
Solution
Open your metabase.XML which is located in c:\Windows\System32\Inetsrv find the line AspMaxRequestEntityAllowed and change it to 10737418243. This is 1GB - of course you can enter another value to suite your needs.
 
NOTE: Before you edit the file, be sure to stop the IIS service first or else you wont be able to save the file. 

Open in new window

0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24203529
Also the number you specify here is in KB:
<httpRuntime maxRequestLength="1550000"/>
0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24203536
Check this for better understanding:
http://msdn.microsoft.com/en-us/library/e1f13641(VS.71).aspx
 
0
 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24203576
ok., in local server we can change the metabase.xml  AspMaxRequestEntityAllowed size.,

But what we have to do for Server.. Am not very comfort to handle the FTP folders and files and so.

Right now i have increased the maxrequestlength.,

Am getting doubts continously by using this method.. :-)

Actually i used to save the filename with somestring or somecombination ., is it possible to change the filename here..

because in the same folder it may contain already a image abc.jpg., once again if i saved the same file name, but image is different, [ what i can do to avoid this situation]

And once again, the dll is exactly free to use for any purpose right..?
0
 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24203801
One more problem, its working very fine with  IE, but its not working with Mozilla FireFox Browser.,

And give me the suggestion about the file name problem too.

thanks..,
0
 
LVL 8

Accepted Solution

by:
Faheem Shaikh earned 2000 total points
ID: 24203871
>ok., in local server we can change the metabase.xml  AspMaxRequestEntityAllowed size.,

>But what we have to do for Server.. Am not very comfort to handle the FTP folders and files and so.
You have to make the same settings on the server as well for the AspMaxRequestEntityAllowed.
But you will be better off by just setting your webconfig on server for

<httpRuntime maxRequestLength="??????"/>
which you have already done i guess. So you should be fine.
>  Actually i used to save the filename with somestring or somecombination ., is it possible to change the filename here..

>because in the same folder it may contain already a image abc.jpg., once again if i saved the same file name, but image is different, [ what i can do to avoid this situation]
One thing you can do is, apply the current timestamp as part of the file name that you upload. Then  this condition will never arise.
>And once again, the dll is exactly free to use for any purpose right..?
The answer is YES.
>One more problem, its working very fine with  IE, but its not working with Mozilla FireFox Browser.,
This is something i have no clue about. :-(
0
 
LVL 2

Author Closing Comment

by:Rajeshk_cgm
ID: 31572625
Really appreciatable answer by faheem29484
0
 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24204068
Really thanks a lot faheem.. for your suggestion and help..

And Sorry i dont know about the current timestamp  concept., ?

and for web.config i have mentioned the maxrequestlenght as 2097151., and ofcourse i have tested with server nearly 50 images size of 8 MB., its working very fine...

0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24204118
It's an honour to be of service. Sharing is learning!!!!!!!
This question is special to me. It earned me my first certification on EE - Master in ASP.NET
BTW: with current timestamp i meant the current system time.
ENJOY!!!!!!!!!!
0
 
LVL 2

Author Comment

by:Rajeshk_cgm
ID: 24204371
Oh., Thats great., Congrates.. !!!!

ya ofcourse i used to do like that when using a single file uploader, but here we are getting all the files as bulk and uploaded with server right, here how we will change the file name.

can you give little briefly.,
have a look of the following code..

if possible can u put the modified code...

 public void ProcessRequest(HttpContext context)
    {
        string temp = context.Session["temp"].ToString();
        string foldername = context.Session["Maker"].ToString();
        string EncryptString = context.Request.QueryString["User"];
        FormsAuthenticationTicket UserTicket = FormsAuthentication.Decrypt(EncryptString);
        
        if (!UserTicket.Expired && context.Request.Files.Count > 0 )
        {
            // get the applications path
            string uploadPath = context.Server.MapPath(context.Request.ApplicationPath + "/" + foldername);
            // loop through all the uploaded files
            for(int j = 0; j < context.Request.Files.Count; j++)
            {
              // get the current file
             HttpPostedFile uploadFile = context.Request.Files[j];
              // if there was a file uploded
             if (uploadFile.ContentLength > 0)
                {
                   // string filename = uploadFile.FileName.Substring(uploadFile.FileName.LastIndexOf("\\"));
                    uploadFile.SaveAs(Path.Combine(uploadPath, uploadFile.FileName));
                         
                }                
            }
        }
        HttpContext.Current.Response.Write(" ");
    }

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question