Tuesday 23 September 2014

Deployment conflicts were detected.

When developing solutions for SharePoint 2010 Visual Studio automatically resolves conflicts when redeploying a solution. By default, user will be prompted with the below message.



  • If you select Resolve Automatically, your list and all of its data will be removed before a new instance of the list is provisioned. 
  • To prevent this, you can set the Deployment Conflict Resolution property of the list instance in the Solution Explorer to None
  • Simply right-click on the list instance project item in VS and select Properties. Then select None from the drop-down list of values:



Thursday 11 September 2014

RSS Viewer Webpart in SharePoint 2010

There can be two types of RSS Feed links.
·         Internal
·         External

Internal RSS Feed Web part

Any RSS Feed link (xml) which is hosted inside a company intranet is categorized as a RSS Feed internal link. To make use of these feeds, we have three options.
·         Change default authentication type NTLM to Kerberos
·         Enable anonymous access on List/Library.
·         Custom RSS Viewer web part

If Kerberos authentication in configured (enabled) on your SharePoint server then you can use an out of the box RSSViewer Web Part to render an RSS feed coming from the internal RSS feed link.To enable Kerberos authentication, follow this link:


If the security configuration is NTLM and you try to configure the RSS view webpart with an internal RSS feed link, it will throw an error like this:

                “The RSS Web Part does not support authenticated feeds.”

In this case, use the custom RSS feed web part

OR

If your web site’s security permits, then give anonymous access to the underlying list/library. To Enable Anonymous access, follw this below link:


External RSS Feed Web part

Any RSS feed link which is hosted on the internet is called an External RSS Feed.
Normally External RSS feed links don’t work as-is on Company Intranet sites, since they use proxy servers to connect to the internet.
In that case use, we have to modified the web.config. Please take a backup of web.config.
<system.net>
      <defaultProxy>
         <proxy usesystemdefault="false" proxyaddress="http://proxyhere" bypassonlocal="true" />
      </defaultProxy>
   </system.net>




Tuesday 9 September 2014

Enable Anonymous Access on SharePoint List or Library

We can enable anonymous access in MS SharePoint 2010 within few clicks.


1. Go to central Administration,under Application Management, click on the Manage web applications. 2. Select your web application and click on Authentication Providers. 
3. Click on "Default"

 

4. Check the "Enable Anonymous Access"


5. Click On Save.
6. Go to your Site --> Site Settings --> Site Permissions. Click on "Anonymous Access" 


7. Select "List and Libraries" 



8.Go to your "List permissions "




9.Click on "Anonymous Access". Select the permissions you want to enable on this list.  


Thursday 3 July 2014

List Template IDs in Sharepoint 2010



Template ID List Name
100 Generic list
101 Document library
102 Survey
103 Links list
104 Announcements list
105 Contacts list
106 Events list
107 Tasks list
108 Discussion board
109 Picture library
110 Data sources
111 Site template gallery
112 User Information list
113 Web Part gallery
114 List template gallery
115 XML Form library
116 Master pages gallery
117 No-Code Workflows
118 Custom Workflow Process
119 Wiki Page library
120 Custom grid for a list
130 Data Connection library
140 Workflow History
150 Gantt Tasks list
200 Meeting Series list
201 Meeting Agenda list
202 Meeting Attendees list
204 Meeting Decisions list
207 Meeting Objectives list
210 Meeting text box
211 Meeting Things To Bring list
212 Meeting Workspace Pages list
301 Blog Posts list
302 Blog Comments list
303 Blog Categories list
1100 Issue tracking
1200 Administrator tasks list

Tuesday 1 July 2014

Access denied using SPSecurity.RunWithElevatedPrivileges - Sharepoint 2010

SPSecurity.RunWithElevatedPrivileges - Sharepoint 2010

--Executes the specified method with Full Control rights even if the user does not otherwise have Full Control.

Whenever we use SPSecurity.RunWithElevatedPrivileges(), it will execute the code under the context of Application Pool identity. Now we can see a scenario where we will get the “Access denied” exception from the code block even if you use SPSecurity.RunWithElevatedPrivileges.

Using SharePoint context with an unauthenticated user does not actually elevate privileges:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    // do something with SPContext.Current.Web 
    // fails with a AccessDenied Exception
    // because SPContext is loaded with the site,
    // not within this delegate block.
   // if anonymous user logged in, context will be loaded with the ANONYMOUS USER's only.
});

So to get actual elevated privileges (i.e., App Pool Identity), you have to reload the context:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(SPContext.Current.Web.Site.Url))
    {
        using (SPWeb oWeb = site.OpenWeb())
        {
            // do something with oWeb
                    // oWeb is loaded with the Application pool identity
        }
    }
});


Happy Coding J..


Tuesday 10 June 2014

Import-SPWeb: The directory does not exist

Import-SPWeb: The directory does not exist

So you've exported a site or list and then when attempting to Import it again, you get an error saying that the directory you are importing from does not exist, right?

My error is below:
Import-SPWeb : The directory D:\Test\Test.cmp does not exist.
At line:1 char:1
+ Import-SPWeb -identity http://mytestsite -Path D:\Test\Test.cmp -NoFileCompression -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : InvalidData: (Microsoft.Share...CmdletImportWeb:
   SPCmdletImportWeb) [Import-SPWeb], SPException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletImportWe
   b

So I ran the export from Central Administration but I did say to include all versions.
I did not check the user security box (which in reality I should have done!), but the problem here was that I did not have FileCompression on in the export from Central Admin.
I added that switch to the cmdlet. So the Import would not work for that reason.

I tried running:
Import-SPWeb -identity http://mytestsite -Path D:\Test\Test.cmp  -Force


Simply removing -NoFileCompression solved the issue and it imported. J

Enjoy Coding.. J


Wednesday 12 March 2014

Service Unavailable HTTP Error 503. The service is unavailable

Solution1:Check for the Application pool status. If it is stopped, start it.
If it is stopped again..
1. Select application pool --> Advanced settings --> set Identity property value to admin account details.
2. Start the application pool again.

Solution 2:
1. Run following cmdlet:
           Set-SPManagedAccount - UseExistingPassword -Identity DOMAIN\SPSAdmin
2. Start the application pool

Sunday 12 January 2014

Add and Remove Event Receiver through Feature SharePoint 2010

1. Add Event Receiver using Visual Studio( Here, I added list leve ItemUpdated event receiver
     Solution -->Add -->Add New Item


2.Add feature reciever and add  the below code

public class FeatureEventReceiver : SPFeatureReceiver
    {
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb spWeb = properties.Feature.Parent as SPWeb;
            try
            {
                using (SPSite siteCollection = new SPSite(spWeb.Url))
                {
                    using (SPWeb web = siteCollection.OpenWeb())
                    {
                        SPList list = web.Lists["ListName"];
                        SPEventReceiverDefinitionCollection spEventReceiverDefinitionCollection = list.EventReceivers;
                        if (!isEventAlreadyAttached(spEventReceiverDefinitionCollection, "AssemblyName"))
                        {
                            SPEventReceiverType spEventReceiverType = SPEventReceiverType.ItemUpdated;
                            spEventReceiverDefinitionCollection.Add(spEventReceiverType, " AssemblyName ", "EventReceiverClassName");
                            list.Update();
                            web.Update();
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                //Log you message
            }
            finally
            {
                spWeb.Dispose();
            }
          
        }
        private bool isEventAlreadyAttached(SPEventReceiverDefinitionCollection spEventReceiverDefinitionCollection, string myAssembly)
        {
            bool eventReceiverAttached = false;
            foreach (SPEventReceiverDefinition spEventReceiverDefinition in spEventReceiverDefinitionCollection)
            {
                if (spEventReceiverDefinition.Assembly.Contains(myAssembly))
                {
                    eventReceiverAttached = true;
                    break;
                }
            }
            return eventReceiverAttached;
        }

        // Uncomment the method below to handle the event raised before a feature is deactivated.

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
           
            SPWeb spWeb = properties.Feature.Parent as SPWeb;
            try
            {
                RemoveEventReceiver(spWeb.Url);
              
            }
            catch
            {
                return;
            }
            finally
            {
                spWeb.Dispose();
            }
        }

        private void RemoveEventReceiver(string siteUrl)
        {
            using (SPSite siteCollection = new SPSite(siteUrl))
            {
                using (SPWeb web = siteCollection.OpenWeb())
                {
                    List<Guid> receiversToRemove = new List<Guid>();
                    SPList list = web.Lists["ListName"];
                    SPEventReceiverDefinitionCollection spEventReceiverDefinitionCollection = list.EventReceivers;
                    for (int i = 0; i < spEventReceiverDefinitionCollection.Count; i++)
                    {
                        if (spEventReceiverDefinitionCollection[i].Assembly.Contains("AssemblyName"))
                        {
                            receiversToRemove.Add(spEventReceiverDefinitionCollection[i].Id);
                        }
                    }
                    if (receiversToRemove.Count > 0)
                    {
                        foreach (var guid in receiversToRemove)
                        {
                            list.EventReceivers[guid].Delete();

                        }
                        list.Update();
                        web.Update();
                    }
                }
            }
        }
    }

Note: Replace ListName and AssemblyName details.