Jul 6
Hide buttons from lists
Posted by Wei in SharePoint Web Parts on 07 6th, 2010| | No Comments »

Simple one... add a content editor web part and add the following code:

<style>
.ms-menubuttoninactivehover{
 display: none;
}
.ms-separator{
 display: none;
}
.ms-splitbuttondropdown{
 display: none;
}
.ms-viewselector{
 display: none;
}
.ms-listheaderlabel{
 display: none;
}
</style>

You'll notice that some of those buttons disappear.

Dec 2

stsadm -o setproperty -propertyname max-template-document-size -propertyvalue 500000000
(hard limit of 500Mb)
 
Then to export the site and import it, run the following commands on your intranet
 
Note: you will need to give full control permissions to whoever is logged in on the intranet server for the site being imported to. What I did was to give full control to that account, then remove the user once the import is completed.
 
stsadm -o export -url http://intranet/path/to/website -includeusersecurity -nofilecompression -filename C:\somebackupfolder

Create the new site on your intranet.

stsadm -o import -url http://intranet/new/site -includeusersecurity -nofilecompression -filename C:\somebackupfolder

Oct 14

Here's a quick code snippet for updating user profile information in SharePoint

    SPSite siteCollection = null;
    SPWeb web = null;
    siteCollection = SPContext.Current.Site;
    web = siteCollection.RootWeb;

    web.AllowUnsafeUpdates = true;
    SPList list = web.Lists["User Information List"];
    SPUser user = web.SiteUsers["DOMAIN\user"];
    SPListItem item = list.Items.GetItemById(user.ID);
    item["FirstName"] = "John";
    item["LastName"] = "Smith";
    item["WorkPhone"] = "55378008";
    item["Office"] = "BigScholar.com";
    item.Update();

The List name needs to remain as "User Information List".

Apr 3

First thing to clear up is this... a document library is not a folder and a folder is not a document library. A folder resides in a document library and the SPFolder class doesn't have the same methods as the SPDocumentLibrary class (unfortunately).

For example, you can get the last modified date of any file within an entire document library, but you can't get the last modified date of any file within a folder within that document library. I found this frustrating because that was exactly what I had to do.

Anyway, when you browse to a document library and click on a folder within that document library, you get a huge URL. One that looks something like http://intranet/site/subsite/DocLib/Forms/AllItems.aspx?RootFolder=%2fsite%2fsubsite%2fDocLib%2fFolderName&blah blah blah. Copy that link into a list with a URL field and sometimes you see this... http://intranet/site/subsite/DocLib/FolderName. Now, that's annoying when trying to figure out what the folder is in the URL that the user pastes.

So firstly, what you need to do is check if there is a value for RootFolder in the URL and if there is, convert it into the shortened version so you can more easily manipulate it.

    if (strURL.Contains("RootFolder="))
    {
        // need to shorten it
        int equalMark = strURL.IndexOf("=");
        int ampersandMark = strURL.IndexOf("&");
        string folderURL = SPEncode.UrlDecodeAsUrl(strURL.Substring((equalMark + 1), (ampersandMark - equalMark - 1)));

        SPSite site = new SPSite(strURL);
        strURL = site.Url + folderURL; // now the url is the link direct to the folder itself.
    }

From this smaller URL, you can get the document library details (see here). Then as far as I know, you have to loop through all the folders in the document library to find the one you are after.

    SPSite site = new SPSite(strURL);
    SPWeb web = site.OpenWeb();

    string[] explode = strURL.Replace(web.Url, "").Split(new char[] { '/' });
    string splitURL = explode[1];
    string splitFolderName = explode[2];

    string docLibName = SPEncode.UrlDecodeAsUrl(splitURL); // (this is also the list name with the location we're after)

    foreach (SPListItem folderListItem in web.Lists[docLibName].Folders)
    {
        if (folderListItem.Name == strFolderName) // compare
        {
            // then now we go through the items in this folder and see if there is anything new
            foreach (SPFile file in folderListItem.Folder.Files)
            {
                // you can now go through each file in that folder
            }
        }
    }

Note that web.Lists[docLibName].Folders is of type SPFolder already so you can manipulate the folder if you need to.

Apr 3

Here's what was happening. I needed to extract the document library name from an intranet URL that a user enters. So they would enter something like this as the URL: http://intranet/site/subsite/DocLib1/Forms/AllItems.aspx and from there I need to extract DocLib1 as SPDocumentLibrary. Problem here is that no matter the depth, I still need to find the document library name and manipulate it as SPDocumentLibrary.

I'm not sure if my way is the best way to do it, but it did work...

            SPSite site = new SPSite(strURL);
            SPWeb web = site.OpenWeb();

            string[] explode = strURL.Replace(web.Url, "").Split(new char[] { '/' });
            string splitURL = explode[1];

            string docLibName = SPEncode.UrlDecodeAsUrl(splitURL); // (this is also the list name with the location we're after)
            SPList thisDocLib = web.Lists[docLibName];

If you do a check for thisDocLib.BaseType, you will find it's of the type DocumentLibrary.

Now, how would it work if it were the folder that we were after instead of a document library?

« Previous Entries