Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Sep 02, 2015 7:59 pm

Is it possible to load a Word document from a URL instead of from a local file system?

This works:
Code: Select all
Document document = new Document();
            document.LoadFromFile("D:\My Documents\testdoc.docx");



but I can't seem to get this to work:
Code: Select all
Document document = new Document();
            document.LoadFromFile("examplesite.com/testdoc.docx");


Ignore the url format. I can't post a URL.

nmobley
 
Posts: 3
Joined: Wed Sep 02, 2015 4:16 pm

Thu Sep 03, 2015 6:03 am

Hello,

Thanks for your inquiry.
It is possible. Here is the sample code for your reference.
Code: Select all
    Document doc = new Document();
    WebClient webClient = new WebClient();
    using (Stream stream = webClient.OpenRead("Your url"))
                {
                        MemoryStream ms = new MemoryStream();
                        stream.CopyTo(ms);
                        doc.LoadFromStream(ms, FileFormat.Docx);
                 }
     doc.SaveToFile("5727.docx", FileFormat.Docx);


Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Thu Sep 03, 2015 4:28 pm

Thanks for the example. That helps me load the document, but I can't seem to retrieve the text from the streamed document. I can do it with the following code when I am loading a document from a local path, but not when using a stream.

Code: Select all
//Initialzie StringBuilder Instance
            StringBuilder sb = new StringBuilder();

            //Extract Text from Word and Save to StringBuilder Instance
            foreach (Section section in doc.Sections)
            {
                foreach (Paragraph paragraph in section.Paragraphs)
                {
                    sb.AppendLine("<p>" + paragraph.Text + "</p>");
                }
            }

nmobley
 
Posts: 3
Joined: Wed Sep 02, 2015 4:16 pm

Fri Sep 04, 2015 4:41 am

Hello,

I could retrieve the text from a streamed document. So could you please offer us your sample document here, or you can send it to us ( support@e-iceblue.com) via email ? It would be very helpful to investigate this issue and then we will update to you ASAP.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Mon Sep 07, 2015 7:47 am

Hello,

How is your issue now?
If the issue still is exist, could you please offer us your sample document?
It would be helpful to replicate the issue and work out the solution for you ASAP.

Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Wed Sep 25, 2019 11:21 am

When i am trying with this code
WebClient webClient = new WebClient();
using (Stream stream = webClient.OpenRead("Any URL"))
{
MemoryStream ms = new MemoryStream();
stream.CopyTo(ms);
documentt.LoadFromStream(ms, FileFormat.Html, XHTMLValidationType.None);
}

it does not load images in Word Document from the HTML Given

sudarshan.podili
 
Posts: 1
Joined: Wed Sep 25, 2019 6:11 am

Thu Sep 26, 2019 8:58 am

Hi Sudarshan,

Thanks for your inquiry.
Regarding the conversion of HTML to Word documents, our Spire.Doc is based on HTML source code, which means you need to make sure that the images can be displayed properly after saving the HTML as a file. I suggest you save the HTML page as a .html file and then open the file to see if the image is displayed properly. If there is any question, please share us with your URL to help further investigate it. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc