c# - download a file from server and then delete on server -
Ok I am downloading a file from one server and I am planning to delete the file But I downloaded it on the server downloaded on the client side.
My download code is working fine, but I do not know when to order the file to be removed.
string filepath = restoredFilename.ToString (); // FileInfo myfile = new FileInfo (filepath) Create a new instance of FileInfo class to get the properties of the file to be downloaded; // If the file exists (myfile.Exists) then check // // Clear the response content Response.ClearContent (); // Add file name and attachment, which will emphasize the open / cancel / save dialog box to show in header response. Adharer ("content-displacement", "attachment; filename =" + myfile. //Response.AddHeader ("content-disposition", "inline; filename =" + name = myfile); // response header add file size in reply Response.AddHeader ("content-length", myfile.Length.ToString ()); // ContentType Response Contact Type = Return Extension (myfile.Extension.ToLower ()); //// type file in the response (in Tronsmitfail to ASP.NET 2.0. ASP.NET 1.1 is to you instead use WriteFile) Response.TransmitFile (myfile.FullName); // response response the ending (); }
Now I know the answer. The end () will stop everything and return the value, so there is another way too.
I need this to delete the file
delete the reserved fileForGI ( Restored filename);
But I do not know where to put it. I tried before and after trying to answer.
add
feedback. Flush (); DeleteRestoredFileForGUI (restoredFilename);
After calling the transmit file () and the response to the call. Call End () (you do not need it).
If that does not work, then ditch the transmit file () and go with it:
stream s = myFile.OpenRead (); Int BitesRad = 0; Byte [] buffer = new byte [32 * 1024] / 32k buffer while ((BytesRed = s.Read (buffer, 0, buffer, lb.) gt; 0 & amp; amp; and response. ISLLT connect) {Response. Type OutputStream (buffer, 0, bytes read); Response.Flush (); }
Comments
Post a Comment