Hi,
I am facing a problem regarding the application/octet-stream.I have written a code that downloads a file stored in the App_Data folder to C:/files/ folder and now what problem I am facing is that when I download the file and open it, it opens from the temporary files folder rather I need it from where I have downloaded the file so that when I click the save button of the opened file it will be saved in the current location. Here's the code that I have written.
string str = Server.MapPath( "App_Data/" + ListBox1.Select edItem);
FileStream fs = new FileStream(str, FileMode.Open, FileAccess.Read );
byte[] fileContents = new byte[fs.Length];
fs.Read(fileCon tents, 0, fileContents.Le ngth);
fs.Close();
FileStream fw = new FileStream("C:/files/" + ListBox1.Select edItem, FileMode.Create , FileAccess.Writ e);
fw.Write(fileCo ntents, 0, fileContents.Le ngth);
fw.Close();
Response.Conten tType = "applicatio n/octet-stream";
Response.AddHea der("Content-Disposition", "attachment ; fileName=\"" + ListBox1.Select edItem + "\"");
Response.Flush( );
//Response.WriteF ile("C:/files/" + ListBox1.Select edItem);
Response.Binary Write(fileConte nts);
Response.Flush( );
Response.End();
lblstatus.Text = "File Downloaded";
Anybody have any idea on how this could be done. Is there a way to specify the path as from where the file should be loaded>
Or can the event from any other application like notepad be handled from C#
Looking forward for reply soon.
I am facing a problem regarding the application/octet-stream.I have written a code that downloads a file stored in the App_Data folder to C:/files/ folder and now what problem I am facing is that when I download the file and open it, it opens from the temporary files folder rather I need it from where I have downloaded the file so that when I click the save button of the opened file it will be saved in the current location. Here's the code that I have written.
string str = Server.MapPath( "App_Data/" + ListBox1.Select edItem);
FileStream fs = new FileStream(str, FileMode.Open, FileAccess.Read );
byte[] fileContents = new byte[fs.Length];
fs.Read(fileCon tents, 0, fileContents.Le ngth);
fs.Close();
FileStream fw = new FileStream("C:/files/" + ListBox1.Select edItem, FileMode.Create , FileAccess.Writ e);
fw.Write(fileCo ntents, 0, fileContents.Le ngth);
fw.Close();
Response.Conten tType = "applicatio n/octet-stream";
Response.AddHea der("Content-Disposition", "attachment ; fileName=\"" + ListBox1.Select edItem + "\"");
Response.Flush( );
//Response.WriteF ile("C:/files/" + ListBox1.Select edItem);
Response.Binary Write(fileConte nts);
Response.Flush( );
Response.End();
lblstatus.Text = "File Downloaded";
Anybody have any idea on how this could be done. Is there a way to specify the path as from where the file should be loaded>
Or can the event from any other application like notepad be handled from C#
Looking forward for reply soon.