In Office Viewer new version, you can use OpenFileFromStream to open a appointed file or open a file in database.
Either you want to open an appointed file or open a file from database, for client side, all what you need do is the
same, like following:
m_oEdrawOfficeViewer.HttpInit();
m_oEdrawOfficeViewer.HttpAddpostString(L”DocumentID”, L”Tester.doc”);
m_oEdrawOfficeViewer.HttpOpenFileFromStream(strDownloadPath,varOpt,varOpt,varOpt);
Before you call function HttpOpenFileFromStream, you should do two things, one is to initialize http for clearing all parameters and cookies in http, another thing is to appoint the file or database record. And then use HttpOpenFileFromStream to send the request to the destinated webpage.
Before HttpOpenFileFromStream send request, it will add a couple of parameters automatically.
m_OAHttp.AddPostArgument(L”EDA_GETSTREAMDATA”, L”EDA_YES”);
This couple of parameters tell the destinated webpage OfficeViewer will received file as stream.
At the web side, webpage will decide to read which file or database reacord accordding to the post parameters.
And you should add boundary flag ‘EDA_STREAMBOUNDARY’ to file data, following is the asp.net demo.
if (Request.Params[“EDA_GETSTREAMDATA”] == “EDA_YES”)
{
String fullFileName = Server.MapPath(Request.Params[“DocumentID”]);
Byte[] fs = File.ReadAllBytes(fullFileName);
Response.Write(“Get Stream Successfully!”);
Response.Write(“EDA_STREAMBOUNDARY”);
Response.BinaryWrite(fs);
Response.Write(“EDA_STREAMBOUNDARY”);
}
14 Responses to “Open a Stream from Server without temporary file”
Leave a Reply
You must be logged in to post a comment.
August 25th, 2007 at 9:33 am
Hi,
Can you provide a complete example of using this function? I’m completely new to use this component and evaluating to have to for my company project.
Beside that, may I know how can I add it as a component for ASP.NET project. I can add the Viewer component in my Window project but not for ASP.NET project.
Please Advice.
August 25th, 2007 at 9:35 am
Hi can you provide the full sample of using Open a stream from server without temporary file to me. I’m evaluating this for my company project.
August 25th, 2007 at 10:34 am
You can find the ASP.NET sample project in the install directory. Please download the Office Viewer Component 5.2 version firstly.
I uploaded an aspx page, you can download it at http://www.ocxt.com/download/UploadAction.aspx.zip.
August 26th, 2007 at 1:53 pm
Hi,
Can you explain more on this :
m_oEdrawOfficeViewer.HttpInit();
m_oEdrawOfficeViewer.HttpAddpostString(L”DocumentID”, L”Tester.doc”);
m_oEdrawOfficeViewer.HttpOpenFileFromStream(strDownloadPath,varOpt,varOpt,varOpt);
August 26th, 2007 at 2:10 pm
Hi,
I had code as the following for my open method as
OA1.HttpInit()
OA1.HttpAddpostString “DocumentID”,”abc.xls”
OA1.HttpOpenFileFromStream “OpenFromStream.aspx”
And then my OpenFromStream.aspx as the following
string fullFileName = Server.MapPath(“abc.xls”);
Byte[] fs = File.ReadAllBytes(fullFileName);
Response.Write(“Get Stream Successfully!”);
Response.Write(“EDA_STREAMBOUNDARY”);
Response.Write(fs);
Response.Write(“EDA_STREAMBOUNDARY”);
When I execute the open method,
then I get runtime error and prompt me for debugging. Please advice
August 26th, 2007 at 3:17 pm
Hi,
I found that my component is 5.1 and now I had successfully download the 5.2 and install on my local.
New problem are:
1. Even I use the viewer to open my excel file, it seem halt and freeze there.
2. I had trace and debug my application, it seem that the program will never go to
if (Request.Params[”EDA_GETSTREAMDATA”] == “EDA_YES”)
Please Advice.
August 27th, 2007 at 6:11 am
Please update the ocx. There is a limitation in the trial version about the function. Now we have removed the limitaion from trial version. You can download the 5.2 version again at:
http://www.ocxt.com/download/OfficeOCXSetup.exe
We added the “OpenFromStream” test codes in the asp.net project too.
August 29th, 2007 at 3:49 pm
Hi,
May I know how am I tell the OCXViewer open a file from my .NET embedded resource file. Why the OCXViewer in window do not have the open from stream feature ? If yes, how am I able to do.
Please Advice, thanks.
September 3rd, 2007 at 7:19 am
Thx a lot for the friendly support in ocxt. I had solved my problem.
give you a 100 mark on your support.
January 8th, 2008 at 6:05 am
ASP CODE:
If l_bWrSreamBoundary Then Response.Write “EDA_STREAMBOUNDARY” While Not l_stream.EOS And Response.IsClientConnected Response.BinaryWrite(l_stream.Read(l_nChunkSize)) Wend l_stream.Close If l_bWrSreamBoundary Then Response.Write “EDA_STREAMBOUNDARY”
May 8th, 2008 at 11:09 pm
Hi, a previous comment asked if it was possible to open a file from an embedded resouce file. I couldn’t find any functionality that would allow this in the trial version 5.3. Is this possible from within a windows application? If so could you show how. Thanks.
July 28th, 2008 at 8:38 am
Hello,
Is it possible to open a file from a database stream without having a running webserver? I would like to get a Word file from a database and then load it into the Office Viewer component without using a temporary file.
Regards,
Joost
July 30th, 2008 at 9:01 am
Lew users failed to use the method to download file from the server. Please open the IIS setting and use IIS in anonymouse mode will make the component work!!!!
October 17th, 2008 at 9:28 am
To joost:
You can get the stream then save it to the temporary folder. Use GetTempFilePath method to return a file name. At last call the ClearTempFiles method to delete the temporary files.