Error -- Could not load file or assembly Aspose.Words

Hi,

we are using Aspose.Words for .Net product.

We have created a Sharepoint Event. We referenced the Aspose.words library from the following path (C:\Program Files (x86)\Aspose\Aspose.Words for .NET\bin\net2.0\Aspose.Words.dll). We realised that System.Web is one of the dependencies and have added System.Web.dll (C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.dll).

We are using Visual Studio 2010, .Net Framework 3.5.

We have added the following code.

using System.Web; 
using Aspose.words;

When we try to use Document class as listed in the code below it throws an error.

Document doc = new Document(@"C:\test.doc");
DocumentBuilder builder = new DocumentBuilder(doc);

Error: Could not load file or assembly ‘Aspose.Words, Version=9.6.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56’ or one of its dependencies. The system cannot find the file specified.

Thanks for your help,

Reetu

Hi

Thanks for your request. System.Web is not available in the .NET Framework 3.5/4.0. In this case NET 3.5 Client Profile excludes System.Web. So please try using the Aspose.Words.dll for full .NET 3.5.

Please try using the latest version of Aspose.Words (9.6.0). You can download this version from here:
https://downloads.aspose.com/words/net

Also see the following link for more information:
https://blog.aspose.com/category/words/

Best regards,

Hi Andrey,

We are currently using Aspose.words for .Net.

We have SharePoint environment where the word 2003 .doc file resides in SharePoint document library.

When we call Document doc = new Document("http://server-name/sites/sitename/... xxx.doc")

we get an error “URI Formats are not supported”

In order to add header/footer to a word document residing in SharePoint document library do we need to use some other Aspose product ?

Please let us know.

Thanks,

-Reetu

Hi

Please try using the following code snippet to read document from web.

string url = "http://localhost/mysite/in.doc";
//Prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "application/msword";
request.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";
//Execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//We will read data via the response stream
Stream resStream = response.GetResponseStream();
//Write content into the MemoryStream
BinaryReader resReader = new BinaryReader(resStream);
MemoryStream docStream = new MemoryStream(resReader.ReadBytes((int)response.ContentLength));
//Create document
Document doc = new Document(docStream);
//Save document on local computer
doc.Save("out.doc");

Best regards.

Thanks a lot Andrey for your quick reply. I appreciate it.

Instead of saving the document on local computer I would like to save the document in document library itself.

So the code would be

Document doc = new Document(docstream);
doc.Save(sharepoint document library URL);

Can I do this. Is there any article on Aspose that explains this.

Thanks for your help.

Thanks,

-Reetu

Hi

Thanks for your request. I think, you can just save the output document to Stream and then use the same technique as described here to save the document in SharePoint document library.

Hope this helps.

Best regards,

Thanks Alexey, it helps. Appreciate your help.

Regards,

-Reetu

Hi Andrey,

Thanks a lot for providing the above code to edit the word 2003 file. Now I need to add header/footer in docx file(office 2007/office 2010). I used the above code where url points to the docx file in sharepoint document library.

After the file is saved, I try to open it. While opening the file it throws an error

"The file cannot be opened because there are problems with the content.

Details - The file is corrupt and cannot be opened."

I realised that the Request.ContentType must be changed and so I set the

Request.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";

and doc.Save(fileStream, Aspose.Words.SaveFormat.Docx);

these two changes should have solved the problem. But I still see the error. Any idea?

Code is listed below. Thanks for your help.

Regards,

-Reetu


HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
// url points to docx file
request.Method = "GET";
if (extension == "doc")
    request.ContentType = "application/msword";
else if (extension == "docx")
    request.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
request.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";
request.Credentials = CredentialCache.DefaultNetworkCredentials;
//Execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//We will read data via the response stream
Stream resStream = response.GetResponseStream();
//Write content into the MemoryStream
BinaryReader resReader = new BinaryReader(resStream);
MemoryStream docStream = new MemoryStream(resReader.ReadBytes((int)response.ContentLength));
//Create document
Document doc = new Document(docStream);
DocumentBuilder builder = new DocumentBuilder(doc);
Section currentSection = builder.CurrentSection;
currentSection.HeadersFooters.Clear();
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
// Specify header title for the first page.
builder.Write("sHeader");
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
// Specify header title for the first page.
builder.Write("sFooter");
fileStream.Write(f1.OpenBinary(), 0, (int)f1.TotalLength);
if (extension == "doc")
    doc.Save(fileStream, Aspose.Words.SaveFormat.Doc);
else if (extension == "docx")
    doc.Save(fileStream, Aspose.Words.SaveFormat.Docx);
f1.SaveBinary(fileStream);
fileStream.Close();
fileStream.Dispose();

Hi

Thanks for your request. Could you please attach your output document here for testing? Also, I think, you should add Response.End() after sending document to client browser. This might resolve the problem.

Best regards,

Hi Alexey,

Thanks for your reply.

I have attached the file that gives the error “File is corrupt” while opening it.

I do not have Response.End() method with HttpWebResponse class. I tried adding Response.Close() at the end of the code but it did not work. To understand more about Response.Close() I read this article which states its better not to use response.Close(). I still tried adding it at the end but it did not work.

f1.SaveBinary(fileStream);
fileStream.Close();
fileStream.Dispose();
response.Close()

Thanks for your help,

-Reetu

Hi

Thank you for additional information. You are right, your document is corrupted. But Aspose.Words does not corrupt the document, it seems it is corrupted upon saving to response. Have you tried do not close and dispose stream? Try to dispose stream after closing the response. Maybe this will resolve the problem.

Best regards,

Hi Alexey,

Thanks for your reply. I tried all the solutions provided but it still does not work.

I am using the same piece of code which works perfect for word 2003 document. Hence we are wondering why the same code for docx file is not working(we have provided diiferent content type and save format). Is there a different way to edit the word 2007/2010 document using Aspose API.

Is it possible to provide a sample example that explains how to edit word 2007/2010 document using Aspose.Words API where the document file resides in Sharepoint document library. That will give us an idea whats wrong in the code provided above.

We are very much interested in purchasing the product but we want to test the API for doc/ docx. Doc works but docx is throwing this error.

We very much appreciate the help.

Thanks,

-Reetu

Hi Andre,

I’m having a similar problem. I have installed ASPose Words for .NET, to use in a Sharepoint Workflow being developed in VS 2008. I have tried referencing each of the .NET version DLLs as per your post, but still have the same issue.

WinWF Internal Error, terminating workflow Id# 4e89362b-eca7-402c-a994-0b21b7582747
System.IO.FileNotFoundException: Could not load file or assembly ‘Aspose.Words, Version=9.6.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56’ or one of its dependencies.

I have written a Console App on the same box that works fine. Is there some sort of permissioning change I need to make to get this working with Sharepoint ?

Thanks,

James

Hi Reetu and James,

Reetu, thank you for additional information. Have you tried saving the document to file? Is the document saved to file still corrupted? Also, please try to clear file stream before saving the document into it.

James, Thanks for your request. Pleas make sure that you properly added reference to Aspose.Words to your application.

Best regards,

The issues you have found earlier (filed as WORDSNET-333) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.