Home
IPhone SMS To Gmail
Consulting
Blog
Software
Projects
Links
About
Contact
Blog
Facebook
Twitter
LinkedIn
|
<< 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
Reading Digital Signatures from InfoPath Forms in MOSS 2007 and WSS 3.0 Workflow
Fixing MOSS/WSS SharePoint errors with Alternate Access Mappings
Understanding SharePoint Template Ids
First Version of SharePoint Validator now available on CodePlex
Retrieving data from SharePoint SOAP Requests using LINQ
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("nmessage=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:
Please enter the text from the image:

|