Working with list item attachments is not the best option, but it makes sense at certain points. For example it is a good place to store a pdf-version of your list item or other additional information to the listitem.
If you add an attachment to the list, SharePoint stores the listitem and then tries to upload your attachment. If the attached file has an incorrect filename or characters which are not allowed, the file will not be attached, but the list item will be saved. That’s not so cool, if you’re running workflows on your list.
One possibility is to validate the file name before the save event occurs. Continue reading →
SharePoint offers a lot of options to create custom list forms like jQuery, SharePoint Designer, InfoPath (last Release) and of course ASPX forms. Regarding the last point i demonstrated a shorter “how to” at the Shareconf 2014 in Düsseldorf and would like to share the idea behind the ASPX Forms in this post.
The ASPX Forms (SPForms) which i mean are based on the use of the rendering templates along with ascx user controls.
The rendering template contains all elements which are needed by the listform. You can find the default rendering templates used by SharePoint in the 14 Hive or 15Hive in the controltemplate folder. It is the user control DefaultTemplates.ascx in which you’ll find the “Listform” template. Copy this one and add in your solution the mapped folder for controltemplates. In your user control add the copied template and rename the template id.
How practically would it be if a word document could be filled with some values at predefined places (like placeholder)? In one of my customer projects the requirements were like this:
The customer manages his service agreements in a SharePoint list. Endusers type in the data in a normal SharePoint form. After that they can generate a word document with exactly these data. The data will be transformed into a word template for those agreements. So it is obvious that the data from the sharepoint listitem should be displayed and saved in the word template at certain predefined places. And this scenario can be true by using openxml.
Let me explain with an example more simple. We just insert values from c# into the word document. I’ll show you what you need to do in word and what you need to do in code. Continue reading →
Customer sometimes wanna send an email with their documents as attachment. If the documents are stored in a a SharePoint library, there is a small difference than if they are stored in a folder on the server. So this piece of code might help you to send the mail including the attached file from SharePoint library. The important step is to use the WebClient and Download Data method.
WebClient webClient = new WebClient();
webClient.Credentials = CredentialCache.DefaultNetworkCredentials;
fileUrl = "your SharePoint File Path absolute";
byte data = webClient.DownloadData(fileUrl);
MemoryStream fs = new MemoryStream(data);
fileName = "Your filename.xx";
attachment = new Attachment(fs, fileName);