Rajeshk_cgm
asked on
Muliple File Uploader in asp.net
http://ajaxuploader.com/
This uploader is just like how the gmail files are uploading,
i need exactly uploading multiples files like that.,
This uploader is just like how the gmail files are uploading,
i need exactly uploading multiples files like that.,
ASKER
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.,
ASKER
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.... :-(
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.... :-(
This should server your purpose, you can modify the code to get the upload path as per your liking:
http://dotnetslackers.com/ articles/a spnet/Uplo ad_multipl e_files_us ing_the_Ht mlInputFil e_control. aspx
http://dotnetslackers.com/
ASKER
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
http://weblogs.asp.net/jstengel/archive/2008/04/25/flash-file-upload-server-control.aspx
Yes you can use it, its free. Check if you have proper access setup for writing a file to the remote server.
ASKER
i have checked, we have right option for that folder., am sure about that., but still images are not saving inside that folder.,
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.
ASKER
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.ProcessReques t
Try
'System.Threading.Thread.S leep(5000) 'Slow down for testing only!
Dim myFile As HttpPostedFile = context.Request.Files(0)
Dim RootPath As String = context.Server.UrlDecode(c ontext.Req uest.Query String("Pa th"))
If System.IO.File.Exists(cont ext.Server .MapPath(R ootPath & myFile.FileName)) Then
If CBool(context.Request.Quer yString("O verwrite") ) Then
myFile.SaveAs(context.Serv er.MapPath (RootPath & myFile.FileName))
Else
context.Response.Write("50 0") 'File already exists and will not be overwritten.
End If
Else : myFile.SaveAs(context.Serv er.MapPath (RootPath & myFile.FileName))
End If
context.Response.Write("20 0") 'IMPORTANT! Respond Ok.
Catch ex As Exception
context.Response.Write("50 0") 'IMPORTANT! Respond not Ok.
End Try
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.Is Reusable
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 />
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
<%@ 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"
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
}
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.ProcessReques
Try
'System.Threading.Thread.S
Dim myFile As HttpPostedFile = context.Request.Files(0)
Dim RootPath As String = context.Server.UrlDecode(c
If System.IO.File.Exists(cont
If CBool(context.Request.Quer
myFile.SaveAs(context.Serv
Else
context.Response.Write("50
End If
Else : myFile.SaveAs(context.Serv
End If
context.Response.Write("20
Catch ex As Exception
context.Response.Write("50
End Try
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.Is
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 />
ASKER
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
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
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 /FlashUplo ad.aspx
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/arti cles/asp-n et-file-up load-secur ity-permis sions.aspx
http://bytes.com/groups/ne t-asp/5783 90-file-up loading-pe rmission
http://msdn.microsoft.com/ en-us/libr ary/dwc1xt hy.aspx
Refer to these links:
http://www.kodyaz.com/arti
http://bytes.com/groups/ne
http://msdn.microsoft.com/
ASKER
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="UploadCo mplete()"
FileTypeDescription="Image s" FileTypes="*.gif; *.png; *.jpg; *.jpeg"
UploadFileSizeLimit="18000 00" TotalUploadSizeLimit="2097 152" />
i dont know where i did mistake......
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="UploadCo
FileTypeDescription="Image
UploadFileSizeLimit="18000
i dont know where i did mistake......
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.
Make sure all the multiple server upload paths have the proper permissioning setup for IIS_USR/ASPNET user account.
ASKER
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..?
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..?
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.
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.
ASKER
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]
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]
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.
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.
Also the number you specify here is in KB:
<httpRuntime maxRequestLength="1550000" />
<httpRuntime maxRequestLength="1550000"
ASKER
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..?
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..?
ASKER
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..,
And give me the suggestion about the file name problem too.
thanks..,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Really appreciatable answer by faheem29484
ASKER
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...
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...
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!!!!!!!!!!
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!!!!!!!!!!
ASKER
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...
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(" ");
}
http://www.codeproject.com
http://weblogs.asp.net/jst