Friday, February 17, 2012

Accordian menu in SharePoint 2010

There are several cases when we are required to customize left navigation's OOB behavior. In my resent project I was required to create accordion style menu so that it will fit in page resolution. I implemented this using Jquery.

See below simple implementation, below code refers directly to code.jquery.com latest available jquery file.  Alternatively you can download jquery file and upload it to sharepoint library and then refer it to implement Accordion style left navigation.

Just add below code in V4.master or Custom Master Page

<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function (){
    $("div.menu-vertical>ul.root>li.static>a").toggle(function ()   
    {
        $(">ul", $(this).parent()).show("fast");
    },
    function () {
    $(">ul", $(this).parent()).hide("fast");
    };
    $("div.menu-vertical>ul.root>li.static>ul.static").css("display","none");
    var s = $("div.menu-vertical>ul.root>li.static>ul.static>li.selected").parent();
    var p=s.parent();
    p.find('ul').css("display","");
    });
</script>
 
Use the ‘Comments’ form to share your thoughts.

Thursday, February 9, 2012

Reading / Getting and Updating SharePoint Hyperlink column Value (SPFieldUrlValue)

This is pretty simple implementation, but you have reached to this post means may be you are having some problem with reading or updating values for the SharePoint Hyperlink column.


using (SPSite site = new SPSite("http://SPsiteURL"))
{
    using (SPWeb web = site.OpenWeb("WebName"))
    {// Get the list
        SPList list = web.Lists["ListName"];       // Create a link field value.
        SPFieldUrlValue HypLinkField= new SPFieldUrlValue();
        HypLinkField.Description = "SharePoint Developer Center";
        HypLinkField.Url = "http://sharepoint.com";// Create a new list item and set the URL field value.
        SPListItem sListItem = list.Items.Add();
        sListItem[SPBuiltInFieldId.URL] = HypLinkField;
        sListItem.Update();
    }
}

First I will show you code which will do update to the existing hyperlink column value. In above code sample, SPFieldUrlValue represent SharePoint Hyperlink column. Hyperlink column has two properties, one contains description and other contains actual web url. above example shows how to assign both values.

Now,to read URL property of the Hyperlink column, follow below steps.

Item["SP-HyperLinkColumn"] = "http://www.msdn.com, MSDN Microsoft";
Item.Update(); 

Don’t forget to introduce space after comma, which actually indicates that it is description of the Hyperlink Column.

Or Alternate approach is,

SPFieldUrlValue MyURL = new SPFieldUrlValue();
MyURL.Description = "MSDN Microsoft";
MyURL.Url = "http://www.msdn.com";
Item["SP-HyperLinkColumn"] = MyURL;

Please leave your comments/feedback.
 

Wednesday, February 8, 2012

App Store in SharePoint 2013 [The Marketplace]

There are more news about Microsoft is planning to include a new App store in SharePoint 2013.

The Marketplace will provide you the application which are easily installable in the environment like we do have with iPhone (App Store) and Android Market with similar features and components for SharePoint.

Microsoft already launched Beta of the Office 365 Marketplace in 2011. It's an online app store for Office 365, Microsoft's online version of Office, but more interestingly it also is an online app store for SharePoint.

Still, hard to count out anything related to SharePoint and we'll just have to see if this succeeds in spite of the slow start.

SharePoint is the real key for the Marketplace.

Thursday, September 22, 2011

Visual Studio Debugger Error: The web server process that was being debugged has been terminated by Internet Information Services (IIS). This can be avoided by configuring Application Pool ping settings in IIS. See help for further details.


STEP to fix this:
Run Internet Information Services (IIS) [ if you don’t know then follow the steps to find it.]

1.       Open the Administrative Tools window.

2.       Click Start and then choose Control Panel.

3.       In Control Panel, choose Switch to Classic View, if necessary, and then double-click Administrative Tools.

4.       In the Administrative Tools window, double-click Internet Information Services (IIS) Manager.

5.       In the Internet Information Services (IIS) Manager window, expand the node.

6.       Under the node, right-click Application Pools.

7.       In the Application Pools list, right-click the name of the pool your application runs in, and then click Advanced Settings.

8.       In the Advanced Settings dialog box, locate the Process Model section and chose one of the following actions:

 *.Set Ping Enabled to False.

—or—

*.Set Ping Maximum Response Time to a value greater than 90 seconds.

Explanation:

Setting Ping Enabled to False stops IIS from checking whether the worker process is still running and keeps the worker process alive until you stop your debugged process. Setting Ping Maximum Response Time to a large value allows IIS to continue monitoring the worker process.

9.       Click OK.

Wednesday, September 21, 2011

OWSTimer unhandled exception popup – System.Security.Cryptographic.CryptographicException


Here’s the resulting event log error:

An unhandled exception occurred and the process was terminated.
Application ID: DefaultDomain
Process ID: 6148
Exception: System.Security.Cryptography.CryptographicException
Message: Keyset does not exist
StackTrace: at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
at System.Security.Cryptography.SafeProvHandle._FreeCSP(IntPtr pProvCtx)
at System.Security.Cryptography.SafeProvHandle.ReleaseHandle()
at System.Runtime.InteropServices.SafeHandle.InternalFinalize()
at System.Runtime.InteropServices.SafeHandle.Dispose(Boolean disposing)
at System.Runtime.InteropServices.SafeHandle.Finalize()

Cause of the error is when SharePoint 2010 and Visual Studio 2010 are both installed on the same machine you may see this error every 24 hours. This occurs when the OWSTimer service has a regular process recycle and in the shutdown of the old process an exception is raised. The exception doesn’t interfere with the normal process shutdown and recycle and is only ever seen if you have a JIT debugger installed on the machine.

You can ignore these exceptions and close the window.
You can stop the popup exception message by disabling JIT debugging on your machine. THIS WILL DISABLE JIT DEBUGGING FOR ALL APPLICATION ON THE MACHINE.

Follow the steps to configure the server  which will not show a dialog when an unhandled exception occurs, use the registry editor to delete the following registry keys:

· HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger
· HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\DbgManagedDebugger

On a 64-bit operating system also delete the following registry keys:

· HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger
· HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\DbgManagedDebugger

More details on JIT Debugging are at:
http://msdn.microsoft.com/en-us/library/5hs4b7a6(VS.80).aspx

Wednesday, September 14, 2011

SharePoint Connection Error

--------------------
SharePoint Connection Error
--------------------
Cannot connect to the SharePoint Site: http://yoursharepointsite. Make sure that the site URL is valid, that the Sharrepoint si running on the local computer, and that the current user has the necessary permissions to access the site.

Additional information:

"Cannot connect to the SharePoint site: http://yoursharepointsite.. Make sure that this is a valid URL and the SharePoint site is running on the local computer. If you moved this project to a new computer or if the URL of the SharePoint site has changed since you created the project, update the site URL property of the project."




Resolution to this problem is.

1. Add current user as FARM administrator.
2. Add user as Site Collection administrator.
3. Give user permission on Database as DBO and DBO.OWNER on SharePoint_Config Database and site collection Content Database.

This will resolve the issue.

Friday, September 9, 2011

Show Quick Launch on SharePoint 2010 Custom Webpart Page

When you create a webpart page on SharePoint 2010 by default it will not have the quick launch will vanish.

All you needed to do is edit the page in SharePoint Designer and remove the following lines:


< asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server">
< asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server">




You also need to delete the following:

< style type="text/css">
body #s4-leftpanel {
display:none;
}
.s4-ca {
margin-left:0px;
}


Done. Now refresh the page and the quick launch will now display on the web part page.

Thursday, August 25, 2011

Get DLL Out of The GAC

DLLs once deployed in GAC (normally located at c:\windows\assembly) can’t be viewed or used as a normal DLL file. They can’t be directly referenced from VS project. Developers usually keep a copy of the original DLL file and refer to it in the project at development (design) time, which uses the assembly from GAC during run-time of the project.

During execution (run-time) if the assembly is found to be signed and deployed in GAC the CLR automatically picks up the assembly from the GAC instead of the DLL referenced during design time in VS. In case the developer has deleted the original DLL or don't have it for some reason, there is a way to get the DLL file from GAC. Follow the following steps to copy DLL from GAC
  1. Run regsvr32 /u C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\yourdllname.dll
  2. yourdllname.ddl is an explorer extension DLL that gives a distinct look to the GAC folder. Unregistering this file will remove the assembly cache viewer and the GAC folder will be then visible as any normal folder in explorer.
  3. Open “%windir%\assembly\GAC_MSIL”.
  4. Browse to your DLL folder into the deep to find your DLL.
  5. Copy the DLL somewhere on your hard disk and refer it from there in your project
  6. Run "regsvr32 /i %windir%\Microsoft.NET\Framework\<.NET version directory> \yourdllname.dll" to re-register the shfusion.dll file and regain the original distinct view of the GAC.

Thursday, August 11, 2011

Add / Upload document to Document Library using SharePoint Object Model

Below is the code to upload document to SharePoint Document Library with all the metadata you wanted to update.


String fileToUpload = @"C:\FileNamePath.txt";
String sharePointSite = "http://urSharePointsite.com/sites/";
String documentLibraryName = "Shared Documents";

using
(SPSite oSite = new SPSite(sharePointSite))
{
   using
(SPWeb oWeb = oSite.OpenWeb())
   {
        SPFolder myLibrary = oWeb.Folders[documentLibraryName];

        //upload document
        String fileName = System.IO.Path.GetFileName(fileToUpload);
        FileStream fileStream = File.OpenRead(fileToUpload);

        // Upload document
        SPFile spfile = myLibrary.Files.Add(fileName, fileStream, true);

        SPListItem spLibItem = spfile.Item;


        spLibItem["Title"] = "Document Title";
        spLibItem["Field2"] = "Field2 Value";
        spLibItem.Update();
     }
}