i want to open a doc in browser withoun dialog-window open\save
i have this code
1FileInfo fileInfo =new FileInfo(e.Item.Cells[10].Text);
2 Response.Clear();
3 Response.ContentType ="application/vnd.ms-word;name=" + fileInfo.Name;
4 Response.AppendHeader("Content-Disposition","inline; filename=" + fileInfo.Name);
5 Response.AppendHeader("Content-Length", fileInfo.Length.ToString());
6//Response.OutputStream.WriteByte(7 Response.WriteFile(e.Item.Cells[10].Text);
8 Response.Flush();
but after it i still have window open\save."inline" don't help me, but all say about it
i need your help!
does anybody know??
Try removing line number 4 from ur code
line 4 is the main line , because containe word 'inline' it say browser to open file in browser window(it describes in rfc). line 4 must be present
Hi, you should not use AppendHeader(Content-Disposition) it forces the Open/Save dialogue. The following has been converted from C# to VB.NET
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
'Set the appropriate ContentType.
Response.ContentType = "Application/pdf"
'Get the physical path to the file.
Dim FilePath As String = MapPath("acrobat.pdf")
'Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath)
Response.[End]()
End Sub
If you want the tutorial that goes with the above code go to the link below, it is written in C# but you will get the idea. Hope this helps.
http://support.microsoft.com/kb/306654
Hi kkk111,
I'm not sure why you append fileInfo.Name after the ContentType. The MIME type should be right too. Please use "application/vnd.ms-word" or "application/msword" instead.
now i use this code
context.Response.Clear();//context.Response.ContentType = "application/vnd.ms-word"; context.Response.ContentType ="Application/msword"; context.Response.AppendHeader("Content-Disposition","inline; filename=" + fileInfo.Name); context.Response.AppendHeader("Content-Length", fileInfo.Length.ToString()); context.Response.WriteFile(file);//context.Response.Flush(); context.Response.End();but the stupid window with buttons open\save still show up
need to open an existing word document from asp.net page(in the browser itself)
used response.contenttype="application/msword"
U can also look into the site :http://support.microsoft.com/kb/178222
How to launch word from Internet Explorer
kkk11:
but the stupid window with buttons open\save still show up
Hi,
Glad, shravan_sai provides an alternative solution. You can try his solution too.
it looks like you don't want the dialog prompting to choose whether to open or save the file. I did see this dialog even though Content-disposition is set as "inline". There is a check box "Always ask before opening this type of file." right in the prompt dialog, you can uncheck this. This feature is ebled for security reason.
I'm using IE 7.0 for testing, and the code is following:
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "application/ms-word";
Response.AddHeader("Content-disposition", "inline; filename=abc.doc");
String path = Server.MapPath("abc.doc");
Response.WriteFile(path);
Response.End();
}
0 comments:
Post a Comment