Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Monday, November 26, 2018 4:00:00 AM(UTC)
Vicki2018

Groups: Registered
Posts: 29

Thanks: 3 times

The following code is copied from the DocumentFactory from the Document Viewer Demo.

DocumentFactory.DownloadDocument(cache, documentId, 0, -1, outputStream);

Is it possible to convert the outputstream to a local file?
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Monday, November 26, 2018 10:02:28 AM(UTC)
Anthony Northrup

Groups: Registered, Tech Support, Administrators
Posts: 199

Was thanked: 28 time(s) in 28 post(s)

Hello Vicki,

If you're wanting to output to a file, you can simply provide a FileStream. Below is an example using the code you sent previously:
Code:

using (var outputStream = System.IO.File.OpenWrite(someFilePath))
    DocumentFactory.DownloadDocument(cache, documentId, 0, -1, outputStream);

Thanks,
Anthony Northrup
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 
#3 Posted : Tuesday, November 27, 2018 4:28:36 AM(UTC)
Vicki2018

Groups: Registered
Posts: 29

Thanks: 3 times

Hi, it works.
May I have a further question, whether I can get the stream to memorystream?
 
#4 Posted : Tuesday, November 27, 2018 5:07:55 AM(UTC)
Vicki2018

Groups: Registered
Posts: 29

Thanks: 3 times

I note that all the download file will return as a HttpResponseMessage, then the URL will be opened in browser.

Is it possible that I can have the file downloaded as memorystream (so that I can attach it in an email), no new browser will be shown?
 
#5 Posted : Tuesday, November 27, 2018 10:52:31 AM(UTC)
Anthony Northrup

Groups: Registered, Tech Support, Administrators
Posts: 199

Was thanked: 28 time(s) in 28 post(s)

Hello Vicki,

I'm not sure I understand your question. I'm not aware of anything being automatically opened in a browser when using our C# DocumentViewer demo. If you're simply wanting to save to a MemoryStream, you can simply supply it instead of the FileStream:
Code:

using (var outputStream = new System.IO.MemoryStream())
    DocumentFactory.DownloadDocument(cache, documentId, 0, -1, outputStream);

Thanks,
Anthony Northrup
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 
#6 Posted : Tuesday, November 27, 2018 8:11:38 PM(UTC)
Vicki2018

Groups: Registered
Posts: 29

Thanks: 3 times

File Attachment(s):
Doc1.docx (482kb) downloaded 85 time(s).


When I click "local save", a new page is prompt.

BTW, I tried to use using (var outputStream = new System.IO.MemoryStream()), however, the attachment found in the email is corrupted.

I added the attachment by new System.Net.Mail.Attachment(outputStream , new System.Net.Mime.ContentType("application/pdf")), which should be found for other memorystream.

 
#7 Posted : Wednesday, November 28, 2018 10:25:12 AM(UTC)
Anthony Northrup

Groups: Registered, Tech Support, Administrators
Posts: 199

Was thanked: 28 time(s) in 28 post(s)

Hello Vicki,

The issue here is you're talking about two different portions of the demo. The local save button is within the HTML portion of the demo (the front-end), while anything with streams, direct file I/O, or the DocumentFactory is within the service (the back-end).

The reason a new page is prompted is because the file you are attempting to download is able to be viewed by your browser. If you don't want a new page to be opened, you can simply right-click the link and choose "Save link as...". Unfortunately, a hyperlink can't force the client to download the file when clicking, this behavior is up to the browser. In general, if the file type is supported for viewing within the browser, it will open a new tab using that URL. If the file type is not supported, you will be prompted (by the browser) for saving the file.

As far as the MemoryStream goes, when writing to a stream, its position will typically be positioned at the end of the stream. If you want to use that stream for later purposes, you'll want to reset the position so reading occurs from the beginning of the stream. That can be done by simply setting the Position property to 0:
Code:

using (var outputStream = new System.IO.MemoryStream())
{
    // Write to the stream
    outputStream.Position = 0;
    // Read from the stream
}

Thanks,
Anthony Northrup
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 
#8 Posted : Wednesday, November 28, 2018 8:36:49 PM(UTC)
Vicki2018

Groups: Registered
Posts: 29

Thanks: 3 times

Yes, I missed to reset the position. Thx
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.089 seconds.