Cann`t open some word docs - System.InvalidCastException

Hello Aspose Community
i tried to open a word (doc) document

SPFile templateFile = web.GetFile(TemplateName);
Stream binFile = templateFile.OpenBinaryStream();
Document dstDoc = new Document(binFile, null); //<- throws the failure:

System.InvalidCastException: object of type "System.String" cann't convert into type "System.Byte[]" .
the code works for some word docs but for some others it crashes, i attached a doc which crashes
any ideas?

Hello

Thanks for your request. I cannot reproduce the problem on my side using the latest version of Aspose.Words (9.4.0). I use the following code for testing:

// Get bytes
byte[] docBytes = File.ReadAllBytes("canntOpen.doc");
// Create memorystream
using(MemoryStream docStream = new MemoryStream(docBytes))
{
    // Create document from stream
    Document doc = new Document(docStream);
    doc.Save("out.pdf");
}

You can download the latest version from here:
https://releases.aspose.com/words/net
Best regards,

first, thank you for this fast solution,

it`s working in an Windows.Forms application

but i’m working with documents in a MS SharePoint library and File.ReadAllBytes("canntOpen.doc"); cann’t open uri Formats

i also tried the aspose sharepoint document converter solution, it`s crashing too

Hi

Thank you for additional information. Please try using code like the following to open a document from url:

string url = @"http://localhost/mysite/mydocument.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));
Document doc = new Document(docStream);
// Save document
doc.Save(@"out.doc");

Hope this helps.
Best regards.

Hello Mr alexey noskov
Absolut fantastic work/ service. My problem is solved now.
Thank you.
Best regards