Well, my "dilema" is similar. Basically instead of showing the content on the same page that made the request (let´s say on page 'A', where page 'A' has a button that says "select") I need to show my content on a new page. So far I have this:
void gv_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
String strResult = "", strExtension = "";
String strDirectory, strFileName;
GridView view = (GridView)sender;
Guid __ID = new Guid(view.Rows[e.NewSelectedIndex].Cells[1].Text);
Content c = new Content(Connection, __ID);
//
Byte[] btArray = c.GetFile(ref strResult, out strExtension);
if (btArray != null)
{
strDirectory = "ContentFiles";
strFileName = Page.Request.PhysicalApplicationPath;
strFileName = strFileName + strDirectory;
if (!System.IO.Directory.Exists(strFileName))
System.IO.Directory.CreateDirectory(strFileName);
strFileName += "\\" + "content" + c.HumanNumber + strExtension;
//
System.IO.FileStream fs;
if (!System.IO.File.Exists(strFileName))
fs = System.IO.File.Create(strFileName);
else
fs = new System.IO.FileStream(strFileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
//
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(fs);
writer.Write(btArray);
writer.Flush();
writer.Close();
fs.Close();
Page.Response.Write("<script language=\"Javascript\">var win=window.open('" +
strFileName +
"',null,'width=510,height=255,top=250,left=250','true');</script>");
}
//
if (strResult.Contains("Null"))
lblMessage.Text = "No file was returned. More information: " + strResult;
else
lblMessage.Text = strResult;
}
So the file comes out of the database, into a folder and then has to be shown in a new window. It looks fine until I ran it and I get a JavaScript error saying: "Access Denied". I went on to change the permissions on the folder (mind you I am running this
not on IIS but using the feature that VS2005 has) where the file gets saved, allowing "All" to read, yet nothing. Could somebody give me some pointers?
humble-appre...
Member
32 Points
73 Posts
Re: Download file that is stored in Sql Server database
Aug 19, 2007 07:56 PM|LINK
Hi Kevin,
Well, my "dilema" is similar. Basically instead of showing the content on the same page that made the request (let´s say on page 'A', where page 'A' has a button that says "select") I need to show my content on a new page. So far I have this:
void gv_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { String strResult = "", strExtension = ""; String strDirectory, strFileName; GridView view = (GridView)sender; Guid __ID = new Guid(view.Rows[e.NewSelectedIndex].Cells[1].Text); Content c = new Content(Connection, __ID); // Byte[] btArray = c.GetFile(ref strResult, out strExtension); if (btArray != null) { strDirectory = "ContentFiles"; strFileName = Page.Request.PhysicalApplicationPath; strFileName = strFileName + strDirectory; if (!System.IO.Directory.Exists(strFileName)) System.IO.Directory.CreateDirectory(strFileName); strFileName += "\\" + "content" + c.HumanNumber + strExtension; // System.IO.FileStream fs; if (!System.IO.File.Exists(strFileName)) fs = System.IO.File.Create(strFileName); else fs = new System.IO.FileStream(strFileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write); // System.IO.BinaryWriter writer = new System.IO.BinaryWriter(fs); writer.Write(btArray); writer.Flush(); writer.Close(); fs.Close(); Page.Response.Write("<script language=\"Javascript\">var win=window.open('" + strFileName + "',null,'width=510,height=255,top=250,left=250','true');</script>"); } // if (strResult.Contains("Null")) lblMessage.Text = "No file was returned. More information: " + strResult; else lblMessage.Text = strResult; }So the file comes out of the database, into a folder and then has to be shown in a new window. It looks fine until I ran it and I get a JavaScript error saying: "Access Denied". I went on to change the permissions on the folder (mind you I am running this not on IIS but using the feature that VS2005 has) where the file gets saved, allowing "All" to read, yet nothing. Could somebody give me some pointers?
Thanks!
sql server popup windows Page.Response File Download
humble-apprentice