myGoogleResults

Wednesday, August 7, 2019

Monday, October 18, 2010

passing uploaded document as a steam to a webservice from a sharepoint eventhandler

public override void ItemAdded(SPItemEventProperties properties)
{

//SPFile file1 = properties.ListItem.File;

SPSite site = new SPSite("http://win-ofut34hh848:33738");
using (SPWeb web = site.OpenWeb())
{
SPFolder folder = web.GetFolder("http://win-ofut34hh848:33738/TestDocLib");

int a = properties.AfterUrl.IndexOf('/') + 1;
int b = properties.AfterUrl.Length - (properties.AfterUrl.IndexOf('/') + 1);
SPFile file = folder.Files[properties.AfterUrl.Substring(a,b) ];
//byte[] buffer = new byte[];
//file.SaveBinary(buffer);
Stream m = file.OpenBinaryStream();// new MemoryStream(buffer);

ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client();
sc.GetData(m);
}


//}
}

Calling a web service from a SharePoint event handler

High level steps are as follows:

1. Create the Envent reciver for the list using the Visual Studio templete.
2. Add a web reference to WCF Service.
3. Deploy the Event handler.
4. Register the Event handler.
5. Copy the WebReference folder into Site Virtual Directory in C:\inetpub\wwwroot\wss\VirtualDirectories\[port]
6. Add the App.config code inthe web.config file