Monday, July 30, 2012

Determining the location of your SharePoint 2010 log files

If you're researching a problem with your SharePoint 2010 farm and wish to peruse the SharePoint log files, the standard location for these files is listed as follows:

 C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS

If the directory doesn't contain any files, this most likely indicates that your SharePoint Admin has configured the logs to be sent to another location in order to conserve hard drive space on the C: drive.  If the files have been moved, you can locate them via the following steps:
  1. Open SharePoint 2010 Central Administration
  2. Click on Monitoring
  3. Under Reporting, click on Configure diagnostic logging
  4. Scroll down to the Trace Log extension and locate the Path text box
The information contained in the Path text box is the location where your SharePoint log files are being written.

Thursday, July 19, 2012

Programatically set the initial selected node in an ASP.NET TreeView control

I just ran into a scenario in which I wanted to have the first node in a TreeView control selected the first time the user accesses the given page (i.e. the node is set when the page was initially loaded).  In order to make this work properly, I had to add two lines of code to my PageLoad event that performed the following actions:
  1. Set the selected node of the TreeView control
  2. Trigger the Treeview.SelectedNodeChanged event to simulate the user clicking on the given node
Here is a summarized sample of the code that I added to my PageLoad event that allowed me to simulate a user clicking on the first node when the page was initially loaded:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        // Code that initializes the TreeView
        ...

        treeViewControl.Nodes[0].Select();
        treeViewControl_SelectedNodeChanged(this, EventArgs.Empty);
    }
}
If you'd like to select a certain node, my thought is that you could use the TreeView.FindNode method to locate a particular node in the list. In that case, your code would appear as follows:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        // Code that initializes the TreeView
        ...

        treeViewControl.FindNode(PathOfNode).Select();
        treeViewControl_SelectedNodeChanged(this, EventArgs.Empty);
    }
}
Naturally, you will need to write some additional code to look up the path to your given node, but my hope is that this will give you some idea as to how this might be accomplished.

Tuesday, July 17, 2012

Programatically modify a SharePoint List Item

The following code sample code provides a means for being able to perform actions on a list item in one of your SharePoint List or Document Library.  In this particular instance, I'm reviewing a specific item in a Document Library and performing an action that is dependent on the Check Out status of the associated file:

using Microsoft.SharePoint;

...

Guid siteId = new Guid(...);
Guid webId = new Guid(...);
Guid listId = new Guid(...);
Guid listItemId = new Guid(...);

using (SPSite site = new SPSite(siteId))
{
    using (SPWeb web = site.OpenWeb(webId))
    {
        SPList list = web.Lists[listId];
        SPListItem listItem = list.Items[listItemId];

        web.AllowUnsafeUpdates = true;
        if (listItem.File.CheckOutType.Equals(SPFile.SPCheckOutType.None))
        {
            // Perform the action associated with the file being checked in...
        }
        else
        {
            // Perform the action associated with the file being checked out...
        }
        listItem.Update();
        web.AllowUnsafeUpdates = false;
    }
}

Tuesday, July 10, 2012

Adding an email link to a field contained in a GridView control

The following code sample provides a simple way to add a hyperlink to your GridView control that will launch the user's email client when the user clicks on the link.  In this case, you'll want to focus on the second BoundField control which creates the mailto hyperlink:

<asp:GridView ID="gridViewSiteAdmins" AutoGenerateColumns="false" runat="server"
    EnableModelValidation="True" >
    <Columns>
        <asp:BoundField HeaderText="Name" DataField="Name" />
        <asp:BoundField HeaderText="Email" DataField="Email" DataFormatString="<a href=mailto:{0}>{0}</a>" HtmlEncodeFormatString="false" />
    </Columns>
</asp:GridView>

By the way, there are other routes you can use to do this, but I thought I'd at least give you one that works well for me.