|
-
Aug 31st, 2007, 07:44 AM
#1
Thread Starter
Addicted Member
Open documents in memory in new window
Hi there,
I have a some code to open a speicific path in a new window
Code:
DbUtils.StartTransaction();
VwPersonExerciseIDResultRecord rec = VwPersonExerciseIDResultView.GetRecord("ID=" + this.ID1.Text);
string filename = rec.FileName;
byte[] contents = rec.FileContent;
// Store the contents of attachment temporarily in a file.
// Delete the temporary file if it exists already.
// Save to physicalPath
string physicalPath = this.Page.Request.PhysicalApplicationPath + @"MyResults\" + filename;
if (System.IO.File.Exists(physicalPath))
{
System.IO.File.Delete(physicalPath);
}
// Create the temporary file and store contents.
System.IO.FileStream fs;
fs = new System.IO.FileStream(physicalPath, System.IO.FileMode.CreateNew);
System.IO.BinaryWriter bw;
bw = new System.IO.BinaryWriter(fs);
bw.Write(contents);
bw.Flush();
bw.Close();
fs.Close();
string filepath = this.Page.Request.Url.OriginalString;
filepath = filepath.Replace("Result.aspx", filename);
filepath += "#" + rec.Bookmark;
ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "openPolicy", @"window.open('" + filepath + "','Policy')", true);
Now what i want is to write the filecontent to a window and add the bookmark.
Many thanks for any suggestion,
Figa
-
Aug 31st, 2007, 07:49 AM
#2
I wonder how many charact
Re: Open documents in memory in new window
Would it not be easier to store that information in the database, and add the bookmark using a querystring value that represents the id of the policy stored in the database - then just dump the html stored into a literal control.
/policy.aspx?policyid=32123"
-
Aug 31st, 2007, 12:12 PM
#3
Thread Starter
Addicted Member
Re: Open documents in memory in new window
Thats is what im doing right now...
rec is a record from the database, filecontent is data, filename is the filename(duh)
(data can be a word document, txt file, html file)
But i have to convert the stored data in a file open a new window, and show the file in this new window. What i want is opening this data without first saving it to a file on the server.
Thanks for the response, Figa
-
Sep 7th, 2007, 07:01 AM
#4
Thread Starter
Addicted Member
Re: Open documents in memory in new window
Follow up:
Instead of opening a new page, i added a page to my project and streamed the document there in the page_load event of that page. This way you can get it done from memory:
Code:
DatabaseRecord rec = GetYourRecordHere();
string filename = rec.FileName;
byte[] contents = rec.FileContent;
if(filename.EndsWith(".doc"))
Page.Response.ContentType = "application/msword";
else if(filename.EndsWith(".txt"))
Page.Response.ContentType = "text/plain";
else if(filename.EndsWith(".pdf"))
Page.Response.ContentType = "application/pdf";
else if(filename.EndsWith(".jpg") || filename.EndsWith(".jpeg"))
Page.Response.ContentType = "image/jpeg";
else if (filename.EndsWith(".gif"))
Page.Response.ContentType = "image/gif";
else if(filename.EndsWith(".xls"))
Page.Response.ContentType = "application/vnd.ms-excel";
Page.Response.OutputStream.Write(contents, 0, contents.Length);
Page.Response.End();
This works in IE, not FireFox still trying to get that to work
-
Sep 12th, 2007, 02:30 AM
#5
Thread Starter
Addicted Member
Re: Open documents in memory in new window
Another follow-up...
This is really annoying, everytime i want to stream an office document to the page in the page_load event, the browser opens and closes immediately. But when i test locally everything works fine.
Also when i open the page directly, without a link, the explorer pops up a window which states if i want to open, save or cancel the page, which is fine.
But when i do it with a link, it opens and closes. Is there a way to "prepare" the browser a specific document is being loaded?
(I tried ContentType..didnt work for office documents)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|