Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Friday, August 31, 2012

Custom Web Part to Add document to SharePoint document library

I am categorizing this post into two parts. First part is just to make foundation for this post.

PART I:

To display files and folders of a document library in a tree view style you will need to create a custom web part and for that, you can always refer this link:
http://www.codeproject.com/Articles/37530/Document-Library-Tree-View-Web-Part-for-SharePoint














Now, let's come to the second part which is also the focus of this post.

PART II:

Now suppose, you need to add a document from above web part while refreshing the tree view at the same time.
















Given below is the code to achieve this:



Code Description:
a.) Get document library permission level for logged in user so that 'Add Document' link can be hidden for less privileged users.
b.) Put 'Add document' link on web part with SharePoint look and feel. On clicking, it calls a java script function which is registered using 'RegMyScript'.
c.) It adds document to document library in the SharePoint way and also refreshes library tree view to show the newly uploaded document.

Code Download Link.

Wednesday, July 25, 2012

Accessing web.config of SharePoint Web Application

Finding this information was not very easy, so decided to write this post.

References:
- Microsoft.SharePoint.Administration
- System.IO















Credit goes to KickTech blog post.


Monday, April 23, 2012

Checking Programatically, if Document Library Folder is Hidden

SPFolder doesn't expose any direct property which can be used to analyze if the folder is hidden.

I got stuck into this and could get any solution from Internet also. So decided to write this blog post.

At some places, people are talking about analyzing SPFolder.Properties.Count which should be equal to 21 if the folder is visible. Unfortunately, that's not true !

While looking at SPFolder properties for a hidden folder, I came across 'Item' property (SPListItem type).

For hidden folders, this property was Null regardless of the content in that folder.

For visible folder, it was either 0 or greater than 0 but was not Null even if folder is empty.

So in my view, you should always use 'Item' property of SPFolder to analyze its visibility as follows:

If(SPFolderObj.Item == Null)

//This folder is hidden

Else

//This folder is Visible