Friday, August 12, 2011

Remove "View All Site Content" link for anonymous users in Sharepoint Foundation 2010

1.Go to "Site Actions" ==> "Site Settings"
2.Under Galleries, click on "Master Pages"
3.Select default.master and select “Edit in Microsoft Office SharePoint Designer”.
4.In “Design” view locate “View All Site Content” on the left-hand-site navigation bar and click on it.
5.Go to “Code” view. You will see the following code highlighted:



” AccessKey=”<%$Resources:wss,quiklnch_allcontent_AK%>”/>


6.Change the PermissionString attribute value of the Sharepoint:SPSecurityTrimmedControl XML element from ViewFormPages to BrowseDirectories.
7.Save the default.master. If you login as an anonymous user you will not see the “View All Site Content” link. However when authenticated you will see this option.

Tuesday, January 25, 2011

Programmatically Changing the UI Version in SP2010

In SharePoint 2010, there is the concept of a UI Version and it has a value of 3 or 4. When you upgrade your existing site, it will leave you at Version 3 which looks just like WSS3. However, you have the capability to upgrade to the new SharePoint 2010 visualizations which is version 4. If the administrators have the options enabled, you can change your UI version using the UI itself. It provides the capability to run on Version 3 but get a preview of 4 and then ultimately they can convert to version 4 completely. However, you may want to do this programmatically or you may want to revert back to version 3 after you have turned off preview mode. This quick snippet of code is how you do it.

using (SPSite siteCollection = new SPSite("http://sp2010-server"))
{
SPWeb site = siteCollection.OpenWeb()
{
site.UIVersion = 3;
site.UIVersionConfigurationEnabled = true;
site.Update();
}
}


Sanjay Tiwari

Monday, January 24, 2011

Checking to see if a list exists in SharePoint 2010

The most common way to do this is by using a try/catch block when you try to use the indexer on SPListCollection. Well, I am pleased to tell you about a new method I discovered on SPListCollection that really made my day. The new TryGetList method takes the name of a list and will get this, return a null if the list doesn’t exist. Take a look at this code.

using (SPSite siteCollection = new SPSite("http://moss-server"))
{
SPList myCustomList = siteCollection.RootWeb.Lists.TryGetList("MyCustomList");
// doesn't throw exception!
if (myCustomList != null)
{
// do something

}
}

Quick overview of Master Pages in SharePoint 2010

The first master page we will talk about is v4.master. This is the default team site master page used with version 4 of the UI. This will be the master page you typically use. It provides the ribbon bar and all of the other new visual UI changes such as the site actions menu on the left side.

If you did an upgrade to SharePoint 2010 and haven’t transitioned to the new UI yet, the old master page is still in default.master. This looks just like the master page you use in SharePoint v3 today. It doesn’t have the ribbon bar and the site actions menu is still on the right side.

The search pages by default now use minimal.master. This is a really slimmed down master page with next to nothing on it. It doesn’t even have navigation. I’m not sure why they opted to use this page in Search Center, but I think it provides an issue with people trying to leave the search center. The Office Web Applications also use this master page but that makes a little more sense because it provides more screen real estate.

The last page I will mention is simple.master. This page is used for login and error pages. From what I understand, it can’t be customized (I have no idea why), but it can be replaced.


Thanks
Sanjay Tiwari
www.YashiTech.com

Tuesday, January 18, 2011

Adding a Link to My SharePoint Links Programmatically

Today, I am going to talk about how to work with the My Links functionality in SharePoint 2010 using the API. The first thing to know is that the API calls it a QuickLink. Knowing this makes it that much easier on finding information you need in the SDK to work with them. I figured this list worked like a regular SharePoint list, but in fact it is quite a bit different (which is why I am posting today).

using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;

The first step is to get a reference to the UserProfileManager. You’ll need to pass in a reference to the current SSP by using ServerContext.Current.

UserProfileManager userProfileManager = new UserProfileManager(ServerContext.Current);

After that you get the current user’s profile. Passing true, will create the user’s profile if it doesn’t exist.

UserProfile currentUser = userProfileManager.GetUserProfile(true);

The QuickLinkManager class provides what we need to add, remove, or iterate through the links the user currently has.

QuickLinkManager quickLinkManager = currentUser.QuickLinks;
quickLinkManager.Create("My Quick Link", "http://www.dotnetmafia.com", QuickLinkGroupType.General, null, Privacy.Private);


You can also iterate through the user’s QuickLinks pretty easily using the GetItems() method. For example:

foreach (QuickLink quickLink in quickLinkManager.GetItems())
{
Console.WriteLine(quickLink.Url);
}

Wednesday, July 28, 2010

Create a SharePoint list Dynamically using list template

Somebody sent me question asking how to create a sharepoint list using list template ?
Here is the sample code I have written, its working, if you have any doubt you can send me an email @ s_tiwari05@yahoo.com

Before running this code you have to have a list template created and stored into list template gallery, I am reading it from there and creating one instance of that and using it to create actual link. If you have many sites in he site collection where you want to create list you can put this code into loop and create list in each site.

web1.AllowUnsafeUpdates = true;
//Create Risk-Issue-Chnage List
txtStatus.Text = "";
lblwsname.Text = web1.Url;
SPListTemplate splt;
//Create site
SPSite site=new SPSite();
//Create web
SPWeb web=site.OpenWeb();
SPListTemplateCollection spltc;
try
{
//Retrieve all the list templates from template gallery
spltc = site.GetCustomListTemplates(web);
//Retrieve specific template you are looking for.
splt = spltc["MyListName"];

splColl = web1.Lists;
gd = splColl.Add("MyListName", "MyListTitle", splt);
splColl[gd].Update();


}
catch (Exception ex)
{
SW = File.AppendText("C:\\DeploymentLog.txt");
SW.WriteLine(" Error Occurred while creating list : " + web1.Url + " : " + ex.Message + " " + DateTime.Now.ToString() + " " + ex.StackTrace);
SW.WriteLine("--------------------------------------------------");
SW.Close();
txtStatus.Text = txtStatus.Text + Environment.NewLine + " Error Occurred while creating list, see log for detail......";
}


Sanjay Tiwari
Yashi Technologies LLC
Dallas, Texas

Thursday, May 20, 2010

How to add webpart programmatically in SharePoint webpart page

Adding webpart programmatically in SharePoint webpart page

There are two scenarios:
1. you add a web part that is displaying data for a list, which is called List View Webpart. List view webpart will be created automatically when you create a list.

Here is the code to achieve that.

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;

// Get a reference to a web and a list
SPSite site = new SPSite("http://localhost:8000");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Contacts"];

// Instantiate the web part
ListViewWebPart wp = new ListViewWebPart();
wp.ZoneID = "Left";
wp.ListName = list.ID.ToString("B").ToUpper();
wp.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();

// Get the web part collection
SPWebPartCollection coll = web.GetWebPartCollection("default.aspx", Storage.Shared);

// Add the web part
coll.Add(wp);

2. you add any other web part (e.g. a custom web part or a 3rd party web part like the SmartPart). The




// Get a reference to a web and a list
SPSite site = new SPSite("http://localhost:8000");
SPWeb web = site.OpenWeb();

// Get the web part collection
SPWebPartCollection coll = web.GetWebPartCollection("default.aspx", Storage.Shared);
string dwp = @" Left SmartPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=dd064a5b12b5277a SmartPart.UserControlWebpart ~\UserControls";

coll.Add(dwp);

The first section is the same, get a reference to your site and the WebPartCollection (you don’t need a reference to a list). Next you need to build a XML string containing the information about the web part you want to add. The contents of that string are the same as the DWP file that you need to create to use your custom web parts. A trick to figure out what needs to be in there (especially if you want to specify values for some properties) is to put the web part on a page (using the web interface), and choose “Export” from the dropdown menu of the web part. This will save the contents of the DWP in a file. Finally you can add the web part by calling the Add method of the WebPartCollection and using the dwp string as a parameter.