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 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 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");
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.
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
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.
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.
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.
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.
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 ?
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.