Dec 11, 2011

Copying the File from and to Document Library in SharePoint

Let’s see how to copy the file from and to the document library using object model.
SPSite site = new site("http://siteurl");
using (site)
{
    SPWeb web = site.OpenWeb();
    using (web)
    {
        SPList lib1 = (SPDocumentLibrary)web.Lists["lib1"];
        SPList lib2 = (SPDocumentLibrary)web.Lists["lib2"];
        SPListItem item1 = lib1.Items[0];
        byte[] fileBytes = item1.File.OpenBinary();
        string destUrl = lib2.RootFolder.Url   "/"   item1.File.Name;
        SPFile destFile = lib2.RootFolder.Files.Add(destUrl, fileBytes, true);
    }
}

That’s it! Happy coding!

Displaying Multiple Document Libraries in a Single WebPart

A frequent requirement in the Share Point Projects is Displaying Multiple Libraries together in a single web part. It can be achieved by various methods but I am going to create it through Share Point Designer 2007.
In this article we will come to know how it can be done step by step.

1. The Important thing here to be noted is, whatever may be the number of Document Library going to be merged here, and it should contain the same number of columns and name.
2. If not, this web part won’t work.
3. Create two document libraries (Example : Test1,Test 2)
4. I have created 4 columns such as Type, Title, Name, and Created by in both document libraries.
5. Now, we are going to use the designer 2007 here to proceed.
6. Open the site in designer –> create an .aspx page.
7. In the right side of the designer -> go to Data Source Library -> Linked Sources
8. In the Linked Sources click -> create a New Linked Source.
9. We have Three Tabs here ,
General
a. In General -> Give the Name of the web part
b. In Description-> Give  the Description of your web part
c. In Key Words -> Give the Keywords if u like
Source
a. Click Configure Linked Source -> Pop up window will Show all the  Available Data Sources  as shown below
b. Under the SharePoint Libraries -> add the two document libraries created (Test1,Test 2)
c. Click Next Button


d. Leave the default option (Merger the contents of the data sources….)
e. Click Finish and it show it as shown below.
f. Click ok.
10. Now open the page where you want to add the web part in the designer. Then click “Click to insert a web part” option in the page.
11. In the Data Source Library under Linked Sources you will see the created (here I gave it as Multiple Document Libraries in Single List) the linked source as shown below.

12. Click on the Drop Down in the created Linked Source and click Show Data which will show the “Data Source Details” as shown below.
13. You will see all the columns present in the Document Libraries.
14. Press CTRL and select the columns which you want to display in the Web Part.
15. Then Click on the Insert Selected Fields as…  -> Select Multiple Item View
16. I have selected Name for Use in Forms, Created by and Path from the columns and inserted it in the site which is as follows.
17. We have to format this view so that it looks good to view.
a. First Column is formatted so that select the Format as with Label
b. Then second column  created by in the same way select Format as with Label
c. Finally third column select Format as with hyperlink and give the following the pop-up window.
     Address: /{@FileDirRef}
     Label: {@FileDirRef}
18. We have completed creating the web part. Finally it will look as shown below.


So we are now able to list and view the documents from two document libraries as shown below !!!

Dec 9, 2011

Recommendations for maintaining Infopath performance

I'm creating an InfoPath form that is a bit large and starting to lag so I decided to look up better practices for developing InfoPath forms to maintain performance. Here is what I found online:
- Keep views from being too large or complex. Split large views into several smaller ones with buttons to switch between them.
- Avoid lots of tables (data or layout) in any single view.
- Use Master/Detail to reduce the number of controls in one page, whenever possible.
- Try to use filter to filter the table rows (instead of conditional
formatting).
- Avoid large repeating data structures that can grow to many pages.
-Avoid complex nesting of optional and repeatable sections. These are quite complicated to layout and also can quickly cause a single view to become very large.
- Avoid using Percentage width for your controls if your view contains lots of nested controls. We have seen over 50% improvements by using Fixed Width. You can apply specify a fixed width in the control's properties dialog.
- Be aware of exactly what your business logic does. For example, onAfterChange can fire multiple times for a single edit.
- Rather than querying for all the data then having InfoPath just show a small amount, refine your query and only bring the data you plan on displaying into InfoPath.
- Only get the data you need to load the form. Don't pre-populate data sources that aren't necessary on load.
- Merge static xml data sources into one if you have multiple xml data connections.
- Use Expression Box to display calculated value if you don't need to store the value. If you have business logic to trigger all the calculation, only trigger necessary calculation. Triggering large amount of calculations is costly.
- When using digital signatures, only digitally sign the information you need to. Signing takes a screenshot of the data signed and encodes it in the form. The larger the screenshot, the larger the xml will become with the encoded image.
- Avoid attaching large files to the form. These files are encoded in the xml and can cause issues if they become too large. Provide links over embedding large files if possible.
- Avoid embedding images in a form. For the same reasons as above.

SharePoint Designer opens in contributor mode

We may face some situation, while editing the site using Sharepoint Designer, it will get open in Contributor mode and we will not be able to edit the site, eventhough we have the Site Collection Administrator(SCA) permission.
 By default, Contribute permissions are assigned to the Site Collection Members  group. Even though, we are part of SCA group, if we are member of Site Collection members the Designer will open in Contributor mode.
To overcome this just disable the contributor settings in SharePoint designer by using the below steps:
1. Open the site in SharePoint Designer.
2. Select the Site Tab -> Contributor Settings.
3. Click on Disable Contributor settings button.
Now we will be able to edit the site.

How to convert Infopath form to word document

Sometimes you may need to convert an InfoPath form into a Word document so you can send it to users that either don’t have InfoPath or can’t access your  SharePoint form library. Luckily there is an easy process to do so.
Steps to convert InfoPath form to Word:
1) Open your .xsn InfoPath project file
2) Go to File -> Export To -> Web
3) Enter a name for the file and make sure “Single File Web Page (*.mht;*.mhtml)” for Save as type is selected. Click Export
4) Locate your new .mht file and open it with Word.
5) You should see your InfoPath form in Word. You may have to adjust any checkboxes or radio buttons that may be on the form. Make sure to save the file as a .doc or .docx file type when you’re done