Pages

Showing posts with label SP 2010. Show all posts
Showing posts with label SP 2010. Show all posts

Friday, February 21, 2014

Working with SharePoint List Attachments

SharePoint Lists are a versatile artifact in SharePoint. It can be mend in any way possible to achieve the desired outcome. This is the reason to use List for all the help desk applications. Recently I had to build a helpdesk application but the client wanted to use plain vanilla SharePoint and wanted to avoid custom code and wanted to keep it to bare minimum. Building a simple helpdesk with List and no code is relatively straight forward but the catch here is they already had created a basic structure where they are using a list to collect the information from external users and the information is getting copied to a new list for internal users. This is done to implement separation of permission as mentioned earlier there is no code approach. This is in their POC environment.

Now they wanted to move to production.Implementation is done as follows

1. They are using attachments in the list to get relevant reference documents form external users.
2. Workflow is been used for copying item from one list to other.

The problem that they are facing is attachments are not getting copied. This is interesting because attachments in SharePoint lists are a linked item and is not part of the SharePoint fields. This is what is causing the workflow not to copy the attachment. Also there is no workflow activity that can copy attachment.

The way to solve this problem would be to

1. Create a custom Copy List Item activity with extended functionality to look for attachment and copy it.

2. Customize the List form with Infopath forms and make the attachment to be part of the list item (This I saw working but still could not comprehend why it works.)

3. Write a small event handler (Item Added and Updated(if you are allowing delayed submission) and copy the attachment.

We went with third option and reason for that being though we had to write code we could do it on a Sandboxed solution rather than a Farm solution which would be the case for option 1. Option 2 is ruled out because the client did not like infopath forms. Its good because we now know Infopath form is dead you can read this here)

There is another thing the remember with List Item  attachments. Since List Item Attachments are  stored as collection when you access them in code and these are collection of strings rather than a file. so we have to user getfile method to get the file and add it. Similarly adding an attachment do not need item update as it linked item.

Client is on SP 2010 and I had not  an opportunity to try this out in Client Side Object Model (CSOM or JSOM) which I am planning so that it becomes easy for SP2013 but will update this post after trying with SCOM/JSOM code.

Code :

foreach (string fileName in requestItem.Attachments)
{
  SPFile file =requests.ParentWeb.GetFile(requestItem.Attachments.UrlPrefix + fileName);
                                   properties.ListItem.Attachments.AddNow(file.Name, file.OpenBinary());

}


Monday, January 27, 2014

Get SharePoint WSP from Central Admin

SharePoint solution are most common way of deploying farm solutions in enterprise. There are times when we need to download the solution from central admin for variety of reason. Recently one of the client had a issue where they had multiple version of a DLL and they wanted to know which version of DLL is deployed with the SharePoint Solution. If you do not have a document or Change control process it is difficult to track back. What is a option now because we do not have any documentation on which version was deployed?

Only way out is to get eh WSP that was deployed and extract the WSP to get the DLL and reflect the DLL to find the solution.So far so good but how to get the WSP that was deployed to SharePoint. We cannot download the WSP from central admin through UI. How else we could do this? This is where the powershell panacea of all things SharePoint comes into play.

Powershell command exists to achieve this and we can use this to download the solution from Central Admin. 


$farm = Get-SPFarm  // Get Farm
$file = $farm.Solutions.Item("test.wsp").SolutionFile  // Get SOlution File
$file.SaveAs("c:\test\test.wsp") //Save solution file to Local directory
 
This is how easy to achieve the result using powershell. Make sure you are running this
command with admin privileges. 
 
There is no STSADM equivalent for this solution and I should thank my colleague for
introducing me to this powershell command.