Reading document's content from document library
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;
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'.
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?
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.
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
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
Hello Rein,
You should use dataItem.MediaUrl where the dataitem is your document, image etc.
Kind regards,
Ivan Dimitrov
the Telerik team
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);
Hi Bart,
Can you tell me what you are trying to achieve with this code?
Greetings,
Pavel
the Telerik team
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 );