how to save the content of uploaded files with my Solution when the number of uploaded files are not known

Hello There!,

  First of all i have coded in jscript to add html file input dynamically when we click a button called "Attach". So that we can attach files of any number according to our need.

  Now i want to save the uploaded file's content in a text document that is added with the Solution.

  But this code actually adds the content to the text document correctly if the number of uploaded file is only one .else it just adds the content of all files in to this only one text document.

  Because i don't know how many files will be attached i just want to create text documents dynamically to save the content of the attachements with my Solution

  If you know any solution for my issue , Please let me know!,


Much Obliged & Thanks a Lot,
Myself
0
Sidewinder2
8/13/2008 12:48:49 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

3 Replies
913 Views

Similar Articles

[PageSpeed] 37
Get it on Google Play
Get it on Apple App Store

This may help u a Bit..


If FileUpload1.HasFile Then
path = Server.MapPath(".\Files\" & fileupload1.name & ".txt")
FileUpload1.SaveAs(path)
End If
0
funn01
8/13/2008 2:15:07 PM

Using  a asp.net file input control (FileUpload) will be easier to get the file on the server as you can use funn01's code to save it pretty easily. If it's not a .net control, and it sounds like it isnt, then maybe you can access the file in the Request.Forms collection. I've never tried that myself, but I would think that it is worth a shot.

If you want to use a .net control, but still want the fancy UI of using JS, maybe you can initially have the <asp:FileUpload /> control loaded on the screen, but hidden. Then use JavaScript to show it when the user clicks "Attach".
 

0
JeffRod
8/13/2008 2:41:21 PM

Hello Mate,

The Answer is , 

HttpFileCollection uploads = HttpContext.Current.Request.Files;

for (int i = 0; i < uploads.Count; i++)

 {

HttpPostedFile upload = file;

if (upload.ContentLength == 0)

{

 continue;

}

string c = System.IO.Path.GetFileName(upload.FileName);

 try

 {

 upload.SaveAs("C:\\UploadedUserFiles\\" + c);

Span1.InnerHtml = "Upload(s) Successful.";

 }

catch(Exception Exp)

 {

Span1.InnerHtml = "Upload(s) FAILED.";

}

}


Much Obliged & Thanks a Lot,
Myself
0
Sidewinder2
8/14/2008 4:02:40 AM
Reply: