Reading document's content from document library

Posted by Community Admin on 03-Aug-2018 17:27

Reading document's content from document library

All Replies

Posted by Community Admin on 08-Mar-2011 00:00

Hi

I have uploaded an html document in a document library called ‘staff documents’. When I use the ‘embed link to this file’ option, I get the below url for the document;

http://localhost:7471/myproject/docs/staff-documents/2011/03/07/applicant-home-page-screens.htm?Status=Master

I am using below code to read the html from the above url;

WebClient objWebClient = new WebClient(); 
const string strURL = "myproject/docs/staff-documents/2011/03/07/applicant-home-page-screens.htm"
byte[] aRequestedHTML = null
aRequestedHTML = objWebClient.DownloadData(strURL); //<-- Error on this line

 

Problem is I am getting below error on the highlighted line above.

What is the correct way to reference above document from the document library so the document’s content can be read?

Many Thanks

Regards


Server Error in '/myproject' Application. 
-------------------------------------------------------------------------------- 
   
Could not find a part of the path 'C:\Program Files\Telerik\Sitefinity 4.0\myproject\docs\staff-documents\2011\03\07\applicant-home-page-screens.htm'.  
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.  
    
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files\Telerik\Sitefinity 4.0\myproject\docs\staff-documents\2011\03\07\applicant-home-page-screens.htm'. 

Posted by Community Admin on 10-Mar-2011 00:00

I'm having issues with this as well. I'm building a widget which outputs Excel data as plain HTML. The code works fine inside a separate web application project, but not from within the separate class library containing the widget.

Perhaps this has something to do with the context the application/widget is running in. Hence the virtual subdirectories in the absolute url. If I'm right, the 'embed' url is being routed internally by Sitefinity to the document which is stored in the database, while the actual request is being made to the filesystem.

Any ideas or workarounds on how to solve this?

Posted by Community Admin on 11-Mar-2011 00:00

I was able to solve this using a HttpWebRequest and load the Excel document into a Stream. Not sure if this is going to be of any help to Johns problem, though.

Posted by Community Admin on 14-Mar-2011 00:00

Hello John,

The problem is that the WebClient control you are using needs the full url to this document in order to process it.

All the best,
Radoslav Georgiev
the Telerik team

Posted by Community Admin on 14-Mar-2011 00:00

Hi Radoslav

How can I get the full url for a document from library to pass to WebClient? If this is not possible what is the way to read content of a library document in a string variable?

Thanks

Regards

Posted by Community Admin on 15-Mar-2011 00:00

Hello Rein,

You should use dataItem.MediaUrl where the dataitem is your document, image etc.

Kind regards,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 25-Mar-2011 00:00

I am having a similar problem,

I use the following code

WebClient document = new WebClient();
string docUrl = attachment.Value.ToString();
 
byte[] documentContent = null;
documentContent = document.DownloadData(docUrl);

the docUrl gets the dataItem.MediaUrl from an hashtable but it still gives an error that a part of the path could not be found

Posted by Community Admin on 31-Mar-2011 00:00

Hi Bart,

Can you tell me what you are trying to achieve with this code?

Greetings,
Pavel
the Telerik team

Posted by Community Admin on 31-Mar-2011 00:00

Hi,

I was trying to read the data from the files to be able to send them as documents to clients via e-mail.
But I was able to sort this by doing the following

1.WebClient quote = new WebClient();
2.string docUrl = ConfigurationManager.AppSettings[ "DocumentUrl" ].ToString() + origninalPdf;
3. 
4.byte[] documentContent = null;
5.documentContent = quote.DownloadData( docUrl );
6.MemoryStream stream = new MemoryStream( documentContent );

Regards
Bart Kooi

This thread is closed