Mailing List



NerdyHearn - Blog

<< Back To All Blogs

SharePoint RPC: Corrupted Binary Files

Wednesday, February 25th, 2009

I have recently been doing some work with the SharePoint RPC services and to say the least it is a test-and-try approach as the Microsoft documentation is severely lacking in most cases.

We were coming across a problem with only binary files being corrupted after making the RPC calls for put document. Text files were working normally and upon doing some binary file diffs the working binary files (uploaded through the browser) were different then the originals, but the same in content when opened in Word so a true comparison was out of the question.

We were encoding the entire RPC request as UTF8. What we failed to realize was that because the files were already at a byte-level (which should have been obvious, but sometimes the obvious things are what get you stuck), we were encoding the file twice.

For an example:

POST /sites/mysite/_vti_bin/author.dll
Headers here...

Binary file contents begin here

Of course, don't forget the very important newline delimiter at the end of your RPC method header.

What you are supposed to do is Encoding.UTF8.GetBytes(rpcheaderline) and then append the binary file data to the binary data received from GetBytes.

This is not documented, and can really get you stuck when working with RPC calls in SharePoint.

Hopefully that will help some of you out one day.

SharePointin' Tom Out.


SharePoint CSharp

Related Blogs

Deploying Reporting Services WebParts to SharePoint WSS and MOSS
Determining if MOSS is Standard or Enterprise
SharePoint Error Craziness: Volume 2

SharePoint Error Craziness: Volume 1


Ludo said on Monday, October 12th, 2009 @ 9:09 AM

I've got this problem, but I can't find a workaround.. here the code i'm using:

string method = "method=put+document%3a12.0.4518.1016&service_name=%2f&document=[document_name={0};meta_info=[{1}]]&put_option={2}&comment={3}&keep_checked_out={4}n";
method = String.Format(method, documentName, EncodeMetaInfo(metaInfo), putOption, HttpUtility.UrlEncode(comment), keepCheckedOut.ToString().ToLower());

Byte[] headerBuf = Encoding.UTF8.GetBytes(method);

MemoryStream stream = new MemoryStream();
stream.Write(headerBuf, 0, headerBuf.Length);

int i = 0;

FileStream fs = File.OpenRead(filePath);
i = fs.ReadByte();
if (i != -1)
while (i != -1);

using (WebClient webClient = new WebClient())
webClient.Credentials = CredentialCache.DefaultCredentials;
webClient.Headers.Add("Content-Type", "application/x-vermeer-urlencoded");
webClient.Headers.Add("X-Vermeer-Content-Type", "application/x-vermeer-urlencoded");
result = Encoding.UTF8.GetString(webClient.UploadData(webUrl + "/_vti_bin/_vti_aut/author.dll", "POST", stream.GetBuffer()));
if (result.IndexOf("n

message=successfully") < 0)
throw new Exception("Errore durante l'upload del file");
//throw new Exception(result);

Add A Comment



Email Address: (not public, used to send notifications on further comments)


Enter the text above, except for the 1st and last character:

NerdyHearn - Latest tech news relating to C#, ASP.NET, SharePoint, PHP, general development, and more. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers