More in this section

Forums / General Discussions / Reading document's content from document library

Reading document's content from document library

9 posts, 0 answered
  1. John
    John avatar
    97 posts
    Registered:
    11 Jan 2011
    08 Mar 2011
    Link to this post

    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'. 
  2. Rein
    Rein avatar
    22 posts
    Registered:
    07 Oct 2008
    10 Mar 2011
    Link to this post
    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?
  3. Rein
    Rein avatar
    22 posts
    Registered:
    07 Oct 2008
    11 Mar 2011
    Link to this post
    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.
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    14 Mar 2011
    Link to this post
    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
  5. John
    John avatar
    97 posts
    Registered:
    11 Jan 2011
    14 Mar 2011
    Link to this post

    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

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    15 Mar 2011
    Link to this post
    Hello Rein,

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

    Kind regards,
    Ivan Dimitrov
    the Telerik team
  7. Bart
    Bart avatar
    8 posts
    Registered:
    17 Feb 2011
    25 Mar 2011
    Link to this post
    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
  8. Pavel Iliev
    Pavel Iliev avatar
    140 posts
    Registered:
    18 Jul 2016
    31 Mar 2011
    Link to this post
    Hi Bart,

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

    Greetings,
    Pavel
    the Telerik team
  9. Bart
    Bart avatar
    8 posts
    Registered:
    17 Feb 2011
    31 Mar 2011
    Link to this post
    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
9 posts, 0 answered