Showing posts with label SharePoint 2010. Show all posts
Showing posts with label SharePoint 2010. Show all posts

Thursday, November 29, 2012

Synchronizing SharePoint 2010 user profile with AD

There could be scenarios like these:

- an employee changed his or her name
- an employee changed their mobile phone number
- etc …

The profile information in SharePoint is outdated and needs to be refreshed from AD, where the information is more recent.

The powershell command to do this is:

Get-SPUser –Web http://site | Set-SPUser –SyncFromAD

This command cycles through all the SharePoint users and updates the profile. If you come across any errors it is because there are some accounts in SharePoint or on the local server environment that do not exist in SharePoint. If you go into the appropriate SharePoint site you will notice that profiles have been updated.

Thursday, October 18, 2012

SharePoint 2010 Web Part Error: A Web Part or Web Form Control on this page cannot be displayed or imported. You don’t have Add and Customize Pages permissions required to perform this action

 

I deployed  a SharePoint 2010 on a customer’s system. At first, everything worked OK when users with elevated privileges were testing the part. However, soon after read-only users started experiencing the above error. If a user’s privilege was escalated to “Designer”, it would start working again.

The solution to the problem is to find the SharePointProjectItem.spdata file associated with the web-part and change the IsSafeAgainstScript to true in the <SafeControl..> element.

For Example:

<SafeControls>
    <SafeControl Name="SafeControlEntry1"
        Assembly="$SharePoint.Project.AssemblyFullName$"
        Namespace="Medhat.Ca.MyWebpart"
        TypeName="*"
        IsSafe="true"
        IsSafeAgainstScript="true" />
</SafeControls>

The explanation for this error is that users with privileges below "Design” are not allowed to add web-parts into web pages.

Monday, August 27, 2012

Uploading documents into SharePoint 2010 using OData

I experienced some pain when asked to develop a utility to upload documents into SharePoint 2010 using OData. Therefore, I naturally decided on this post in order to save others the pain I went through. This post explains how to do it using a simple client-side C# command-line application:

Step 1:

Create a C# command-line application in Visual Studio 2010 on the same box as your SharePoint 2010 server. Add a proxy to the SharePoint 2010 OData service on your server. This is done by right-clicking on your project “References” node and choosing “Add Service Reference …”.

image

The service that needs to be consumed is listdata.svc. Enter a URL similar to http://myserver/_vti_bin/listdata.svc then click on the “Go” button. Once the service is found, give the service NameSpace the name ListdataServiceReference.

Step 2:

I placed a text file named bogus.txt in the root of my c: drive with some arbitrary content. I also created a document library named BogusDocumentLibrary in the root site of my SharePoint server. Here is the upload() method code for uploading file c:\bogus.txt into the document library named BogusDocumentLibrary.

private static void upload() {
    string sharePointSvc = "
http://myserver/_vti_bin/listdata.svc";

    using (FileStream file = File.Open(@"c:\bogus.txt", FileMode.Open)) {
        ListdataServiceReference.HomeDataContext ctx
            = new ListdataServiceReference.HomeDataContext(new Uri(sharePointSvc));

       // ctx.Credentials = System.Net.CredentialCache.DefaultCredentials;

        string username = "alice";
        string password = "wonderland";
        string domain = "myserver";

        ctx.Credentials = new System.Net.NetworkCredential(username, password, domain);

        string path = "/BogusDocumentLibrary/Bogus.txt";
        string contentType = "plain/text";
        ListdataServiceReference.BogusDocumentLibraryItem documentItem = new ListdataServiceReference.BogusDocumentLibraryItem()
        {
            ContentType = contentType,
            Name = "Bogus",
            Path = path,
            Title = "Bogus"
        };

        ctx.AddToBogusDocumentLibrary(documentItem);

        ctx.SetSaveStream(documentItem, file, false, contentType, path);

        ctx.SaveChanges();
    }
}

Needless to say, you must resolve the missing System.IO namespace.

Context
The name of the proxy class representing your context is named depending on your site’s name. In my case, my site is named home so the proxy context class is HomeDataContext.

Credentials
If you are accessing the service on the same box or domain as the server then it suffices that you pass on the default credentials with “System.Net.CredentialCache.DefaultCredentials”. Otherwise, if you are on a different domain then you should use the technique described in the code above where the username, password, and domain with access rights to the SharePoint site are passed on to the server.

Document Properties
The item proxy class name that represents the document library depends on the name given to it. In my case, I named the document library BogusDocumentLibrary so the item proxy class name is BogusDocumentLibraryItem. Once an instance of this class in instantiated then the various properties such as ContentType, Name, Path, and Title must be set.

Upload document
Finally, these three lines are responsible for uploading the document:

ctx.AddToBogusDocumentLibrary(documentItem);
ctx.SetSaveStream(documentItem, file, false, contentType, path);
ctx.SaveChanges();

Finally, you can call the upload() method from within your main method and it should all work as long as the appropriate server, text file, and document library exist.

Thursday, February 23, 2012

How do you install a SharePoint 2010 Feature that appears to be missing.

Similar to a previous post, I got the following error while creating the "WIKI Publishing" site collection is SharePoint 2010:

Dependency feature with id 14aafd3a-fcb9-4bb7-9ad7-d8e36b663bbd for feature 'BaseSite' (id: b21b090c-c796-4b0f-ac0f-7ef1659c20ae) is not installed

I determined that 14aafd3a-fcb9-4bb7-9ad7-d8e36b663bbd refers to a feature named "LocalSiteDirectoryControl" from this site:

http://blogs.msdn.com/b/mcsnoiwb/archive/2010/01/07/features-and-their-guid-s-in-sp2010.aspx

I then executed the following command to activate the feature.

INSTALL-SPFEATURE -Path "LocalSiteDirectoryControl"

Thereafter, it was smooth sailing.

Wednesday, February 1, 2012

How do you find out the name of a feature from the GUID in SharePoint 2010?

While trying to import an exported site onto a different SharePoint instance, I encountered the following error:

The site template requires that the Feature {d57f4817-f1f9-42aa-863c-139804c731b0} be installed in the farm or site collection.
Troubleshoot issues with Microsoft SharePoint Foundation.

Correlation ID: 59577f16-fffc-422c-8b16-458cfb62adaf

I needed to figure out what feature was missing on the destination SharePoint 2010 instance. The following Powershell command came in handy:

PS C:\> GET-SPFeature -Identity "d57f4817-f1f9-42aa-863c-139804c731b0"

DisplayName                    Id                                       Scope
-----------                    --                                       -----
FBAManagement                  d57f4817-f1f9-42aa-863c-139804c731b0     Site


It turned out that I had installed a codeplex "Forms Based Authentication Management" feature on the source site that facilitates managing forms-based authentication users with the aspnetdb.mdf database.

Easy way to create a site template in SharePoint 2010

Even though it is not as obvious as in SharePoint 2007, here's an easy way to create a site template for a site that you would like to reuse:

1) Go to the site that you want to create a site template for. Example: http://sp.abc.com/marketing/default.aspx

2)  Add the "_layouts/SaveTmpl.aspx" to the site's URL. Example: http://sp.abc.com/marketing/_layouts/SaveTmpl.aspx

3) This brings you back to the familiar dialog from the SharePoint 2007 days. The site template is saved in the
 root site Solutions gallery under: Site Actions >> Galleries >> Solutions

Cannot find "Team Site" on SharePoint 2010

I installed a SharePoint 2010 web site based on the "Publishing Site" template. When I came to create sub sites I could not find the many templates (including Team Site) that I was accustomed to under SharePoint 2007. It turned out that they included but need to be brought to the surface. Here's how you can make them available:

Site Actions >>  Look and Feel >> Page layouts and site templates

All the templates are in the first listbox. Add them then click OK. Voila... you can now create new sites based on this template.

Friday, August 12, 2011

LINQ to SQL not working on SharePoint 2010

I recently created a user control that was hosted on a SharePoint 2010 server using the Smart Part. This user control contained a simple LINQ to SQL statement that looked like this:

int count = (from address in db.JobsDistribution
                 where address.Active == true
                 select address).Count();

I was getting a compile error: Missing ; on line xx.

It turned that the default compiler used by the SharePoint 2010 web application was .NET Framework 2.0. This issue was fixed by adding the following section in the web.config file of the application within the <configuration> section:


<system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
        <providerOption name="CompilerVersion" value="v3.5"/>
        <providerOption name="WarnAsError" value="false"/>
      </compiler>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
        <providerOption name="CompilerVersion" value="v3.5"/>
        <providerOption name="OptionInfer" value="true"/>
        <providerOption name="WarnAsError" value="false"/>
      </compiler>
    </compilers>
  </system.codedom>