NerdyHearn
Home
Blog

Contact
Mailing List

Software

Active Directory Products
Object Compare
Permission Compare

IPhone Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail

Sites
DocuTerminal
How Long For Me
My Music To Me
SaveMySerials
TypeCount

Blog
Twitter

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...

Body:
put+document:version&...
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.

Tags

SharePoint CSharp

Related Blogs

Receiving null value when using SPFarm.Local on SharePoint 2010
Receiving "The specified file is not a valid spreadsheet or contains no data" when importing to Office 365
Enabling .NET Framework 3.5 in MOSS/WSS After install
Determining if MOSS is Standard or Enterprise
Resolving "The application failed to initialize properly (0xc000007b)" in MOSS 2007

Comments

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);
do
{
i = fs.ReadByte();
if (i != -1)
stream.WriteByte((byte)i);
}
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()));
stream.Close();
fs.Close();
if (result.IndexOf("n

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

Add A Comment

Name:


URL:


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


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. DocuTerminal - Online Filing Cabinet solution. Scan, search and archive your paper documents. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers My Music To Me - Stream your subsonic music collection to your Sonos wireless system TypeCount - Count how often you type across different computers! ServrTrackr - Monitor your SSL certificates, website uptime, and DNS configurations