TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Pramod Kumar Nandagiri
NA
484
0
file download working in firefox and IE is not working in google chrome (chrome downloading default.aspx instead of actual file)
May 19 2012 6:36 AM
Hi following is the code which i have used to download the uploaded file.
private void DownloadFile(object sender)
{
LinkButton lnkBut = (LinkButton)sender;
string fileName = lnkBut.Attributes["fileName"];
String filePath = Server.MapPath("~/FilesUploaded/") + fileName;
FileWebRequest objRequest = (FileWebRequest)WebRequest.Create(filePath);
FileWebResponse objResponse = (FileWebResponse)objRequest.GetResponse();
int bufferSize = 1;
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AppendHeader("Content-Disposition:", "attachment; filename=" + lnkBut.Text);
Response.AppendHeader("Content-Length", objResponse.ContentLength.ToString());
Response.ContentType = this.ResponseContentType(fileName);
// the method supplies the contenttype based on file extention
byte[] byteBuffer = new byte[bufferSize + 1];
MemoryStream memStrm = new MemoryStream(byteBuffer, true);
Stream strm = objRequest.GetResponse().GetResponseStream();
byte[] bytes = new byte[bufferSize + 1];
while (strm.Read(byteBuffer, 0, byteBuffer.Length) > 0)
{
Response.BinaryWrite(memStrm.ToArray());
Response.Flush();
}
Response.Close();
Response.End();
memStrm.Close();
memStrm.Dispose();
strm.Dispose();
}
The above method works fine with the firefox and IE , i am able to download all types of files like zip,txt,xls,xlsx,doc,docx
but when i download the same file from googlechrome , instead of actual zip file, the default.aspx page has been downloaed
Please any one tell me what is the way to get the actual file in google chrome.
Reply
Answers (
2
)
Multiple Image Upload in Asp.net Using C#
Cookies