Thursday 15 August 2013

c# - ASP Downloading file using TransmitFile() -


I am using Response.TransmitFile () to download a zip folder from the folder on my C drive. The folder downloads fine and I increase the files in my downloads folder. Although the problem is in my download folder, a zip file containing the name of the asp page, and inside is the folder I wanted to download the other problem is that I attach a datetime at the end of the zip folder in the upload, but the date The folder is not even at the end of the name.

My upload code looks like this:

  string pnq = httpContext.Current.Request.Url.PathAndQuery; String url = HttpContext.Current.Request.Url.AbsoluteUri.Replace (pnq, "/"); If (FileUpload1.HasFile) {var filename = FileUpload1.PostedFile.FileName; Var uriID = Guid.NewGuid (). ToString (); Var Password = System.Web.Security.Membership.GeneratePassword (7, 2); Filename = filename.Remove (filename.Count () - 4) + "-" + date time.Now Shortcode string () + ".zip"; File name = filename. Change ("", "-"); File name = filename.Replace ("/", "-"); FileUpload1.SaveAs ("C: \\ Upload \\" + File Name); LblUri.Text = url + "UICDownload.aspx? FileID =" + uriID; LblPassword.Text = Password; String file = mappath ("~ / Sample.xml"); XDocument Document = XDocument.Load (file); Dock.rot Add new (excelement ("file", new excelement ("name", file name), new excelment ("uriID", uriID), new excelment ("password", password)); Excellence name = new exclamation ("name", file name); Doc.Save (file); }   

My download code looks like this:

  var text = Request.QueryString ["fileID"]; String file = mappath ("~ / Sample.xml"); XDocument Document = XDocument.Load (file); Var node = doc.Document.Descendants ("uriID"). FirstOrDefault (u = & gt; u.Value.Equals (text)); Var filenode = node. Ancestors ("File") first (); Var tempname = filenode.Element ("name"); Var filename = tempname.Value.ToString (); Var filePassword = filenode.Element ("password"); If (filePassword.Value.ToString () == tbPassword.Text) {Response.Clear (); Response.ContentType = "app / zip"; Response.AppendHeader ("content-dispute", "attachment; fileID =" + text); reaction. Transmission file ("C: \\ Uploads \\" + Filename); Response.End (); }   

Saving XML document to look like this:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; RootElement & gt; & Lt; File & gt; & Lt; Name & gt; Pictures 21-06-2013.zip & lt; / Name & gt; & Lt; UriID & gt; 96e1253b-634b-498-A-b062-61a1a097ee3f & lt; / UriID & gt; & Lt; Password & gt;% zFxRr | & Lt; / Password & gt; & Lt; / File & gt; & Lt; File & gt; & Lt; Name & gt; Test1-21-06-2013.zip & lt; / Name & gt; & Lt; UriID & gt; 44d3d2c8-5c19-4f79-a5e2-66bb023a4d5e & lt; / UriID & gt; & Lt; Password & gt; {Hik6.e & lt; / Password & gt; & Lt; / File & gt;   

Please welcome any suggestions, and tell me if you want me to show any other code. In addition, when files are uploaded to C: \ Uploads folder, zip folders have a date at the end of their name.

Try changing this line to:

  . Append word header ("content-type", "attachment; filename =" + filename);    

No comments:

Post a Comment