Read documents from SharePoint programmatically using C# (Perform a non deleting BizTalk WSS Recieve)

Posted on Updated on

Documents from SharePoint can be read programmatically using C# WebRequest.

On  a BizTalk front, such need occurs when you want to perform a non deleting receive for a sharepoint document.

Consider a scenario where your business process gets triggered and then within needs to read data from sharepoint document library and use it in the process.

BizTalk by default will delete the document from the library after reading the same. One can argue that we can implement a process within, where in the BizTalk  process will read the document and then put it back to the location through a WSS send port and we are done. This is absolutely fine and works as expected but as you see it has more over heads and more failure point. What if while uploading the document it fails and the nest process never gets to read the data and hence resulting in subsequent failures of the main business process. And above all you still need to have a C# code to activate , deactivate your receive location.

What comes in handy in such business scenario is that we can have the Sharepoint location read from a config, preferably SSO Config and then use C# code to read the data to stream or memory stream and then use the same within our business process.

Using memorystream would also help load it to BizTalk XLAng message. Also we can implement a full BizTalk streaming mechanism here to preform our action using IStreamfactory.  More details on this can be found here .

Using the below code we can read the contents to a stream and then to memorystream. UseDefaultCredentials will run the program under current user account or in BizTalk Orch case, under the BizTalk host instance account. So make sure that the user has sufficient rights to read the document library.

We can also key in specific user under the credentials of the request if desired so. Capture

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s