How to open a file
In my project I am trying to open a file. I am storing all the path of the file name along with extensions like .exe,.doc,.xml,etc.....in my database. I am fetching that path and trying to open it.In this I like to open it as a popup window to ask like OPEN,SAVE,CANCEL . Can any one help me to solve this problem. Here is the code:
private void OpenMyFile()
{
string path = GetPath() + ViewState["fileopen"];
FileInfo file = new FileInfo(ViewState["fileopen"].ToString());
SqlConnection con = new SqlConnection(@"server=servername;database=DBNAME;uid=ID;pwd=PWD;max pool size=250;Connect Timeout=0");
con.Open();
cmd = new SqlCommand("select * from filetypemaster where extension='" + file.Extension + "'", con);
myReader = cmd.ExecuteReader();
if (myReader.Read())
{
Response.ContentType =(String)myReader["CONTENT_TYPE"];
myReader.Close();
}
else
{
myReader.Close();
Message("Cannot open selected file");
return;
}
Response.WriteFile(path);
Response.End();
con.Close();开发者_如何学C
}
Thanks in advance
I think what you're asking, in a round about way, is how to get the file save dialog to show on the client?
You need to set the content disposition header. See here: http://www.jtricks.com/bits/content_disposition.html which might help.
Simon
精彩评论