Monday, January 18, 2010

Working with ASP.NET Multiple fileupload control?

I have 3 fileUpload Controls on .aspx page with single upload button..





I want the files to be uploaded to respective folder on basis of file extension.





for example..


.mp3,m3u,amr to audio folder





.jpeg,.gif to images folder





--------------------------------------鈥?br>

Code behind file...





Dim filepath As String = ';C:\Uploads';


Dim uploadedFiles As HttpFileCollection = Request.Files


Dim i As Integer = 0





Do Until i = uploadedFiles.Count


Dim userPostedFile As HttpPostedFile = uploadedFiles(i)





Try


If (userPostedFile.ContentLength %26gt; 0) Then


Label1.Text += ';%26lt;u%26gt;File #'; %26amp; (i + 1) %26amp; ';%26lt;/u%26gt;%26lt;br%26gt;';


Label1.Text += ';File Content Type: '; %26amp; _


userPostedFile.ContentType %26amp; ';%26lt;br%26gt;';


Label1.Text += ';File Size: '; %26amp; _


userPostedFile.ContentLength %26amp; ';kb%26lt;br%26gt;';


Label1.Text += ';File Name: '; %26amp; _


userPostedFile.FileName %26amp; ';%26lt;br%26gt;';





userPostedFile.SaveAs(filepath %26amp; ';\'; %26amp; _


System.IO.Path.GetFileName(userPostedFil鈥?br>




Label1.Text += ';Location where saved: '; %26amp; _


filepath %26amp; ';\'; %26amp; _


System.IO.Path.GetFileName(userPostedFil鈥?%26amp; _


';%26lt;p%26gt;';


End If


Catch ex As Exception


Label1.Text += ';Error:%26lt;br%26gt;'; %26amp; ex.Message


End Try


i += 1


Loop


End SubWorking with ASP.NET Multiple fileupload control?
You can use a FileInfo object to find the extension of the posted file. From there, just use the SaveAs() method of the PostedFile class to save it to its appropriate location. You may want to store these paths in a web config file.





  • eye make up
  • No comments:

    Post a Comment