Wednesday 28 January 2015

Getting $Resources:core,ImportErrorMessage error while importing a .webpart-File to a SharePoint2010

Problem :

I have developed a Visual Web part using VS 2010 and deployed to my Local Development environment directly through Visual studio right click Deploy feature. It works fine.

Now i have to move this webpart to the QA environment where no VS 2010 installed. and the environment is like we have to put the dll file in Bin folder of web application, ASCX control we have to put on Control Template.

Step 1 : so i have put the dll and ASCX control to respective folder.

Step 2 : I added the Safe control entry for that dll in web config.

Step 3 : Now i have exported the .webpart file from my Dev Environment site and import to QA environment site Webpart gallery.

Step 4 : I was able to see the webpart in the custom group of webparts.

Step 5 : when i tried to add the webpart to Page i get the Error " $Resources:core,ImportErrorMessage"

Solution :

I tried with all solution available on Internet like add Safe control entry to web config for DLL. verified the dll Public Key token and same GUID in Safe control. but nothing worked out.

After a long effort, i deployed the solution to my Development environment using VS 2010. it creates a Pkg Folder. 

This folder has a feature folder with .webpart file.

I took this .webpart file and uploaded to QA Environment and then Error Message gone and webpart works perfectly.

so in my view problem was with .webpart file which i have exported from DEV and then try to import to QA. so its always better to take the .webpart file from the pkg Folder and upload to another QA site.

Let me know if anybody has any other solutions.

Updated : Actually today ( 24th MARCH 2015) a found the exact problem when you Upload webpart.xml from your Project Folder to webpart gallery then Webpart still refer Project Assembly file which is not present at server.

So you have to change the Project Assembly reference from the actual DLL refrence which you put either in gac or bin folder while you deploy your webpart.

Thank you Cheers.

Friday 23 January 2015

Get Date Format from Regional Setting of SharePoint 2010 Site programmatically using C#


The requirement was to get the date format for the multilingual web part from the regional setting of a SharePoint site. It had to be achieved programmatically using C# code.


DateTime UtcTime = Convert.ToDateTime(DateTime.Now).ToUniversalTime();
DateTime Timestamp = SPContext.Current.Web.RegionalSettings.TimeZone.UTCToLocalTime(UtcTime);

SPRegionalSettings RegionSet = SPContext.Current.Web.RegionalSettings;

string Dateformat = System.Globalization.CultureInfo.GetCultureInfo(Convert.ToInt32(RegionSet.LocaleId)).DateTimeFormat.ShortDatePattern;

Label1.Text = Convert.ToString(Timestamp.ToString(Dateformat));


you can comment if you are facing still with any issues.

Wednesday 21 January 2015

Get Operating system Information using JavaScript in a SharePoint Page

Issue Description:

Recently Business user has asked me to display the Browser Operating system to the top of a SharePoint Portal home page. So if some SharePoint functionality does not support for Windows XP or other operating system, user should be aware of that.

Restriction: We should not use the Server side code


I planned to go with java script solution to get the OS details. I have searched over the internet and found some of the solution. One of the solution I am going to use below.


 I have added a content Edit webpart to the Home page of the Portal.

Added the below HTML code to the Content Editor.

HTML Code:

create a div element with id "OSMessage" and give the style="Float:right".

Add below code to java script tag


function GetOS()
var nAgt = navigator.userAgent;

        // system
        var os;
        var clientStrings = [
            {s:'Windows 3.11', r:/Win16/},
            {s:'Windows 95', r:/(Windows 95|Win95|Windows_95)/},
            {s:'Windows ME', r:/(Win 9x 4.90|Windows ME)/},
            {s:'Windows 98', r:/(Windows 98|Win98)/},
            {s:'Windows CE', r:/Windows CE/},
            {s:'Windows 2000', r:/(Windows NT 5.0|Windows 2000)/},
            {s:'Windows XP', r:/(Windows NT 5.1|Windows XP)/},
            {s:'Windows Server 2003', r:/Windows NT 5.2/},
            {s:'Windows Vista', r:/Windows NT 6.0/},
            {s:'Windows 7', r:/(Windows 7|Windows NT 6.1)/},
            {s:'Windows 8.1', r:/(Windows 8.1|Windows NT 6.3)/},
            {s:'Windows 8', r:/(Windows 8|Windows NT 6.2)/},
            {s:'Windows NT 4.0', r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},
            {s:'Windows ME', r:/Windows ME/},
            {s:'Android', r:/Android/},
            {s:'Open BSD', r:/OpenBSD/},
            {s:'Sun OS', r:/SunOS/},
            {s:'Linux', r:/(Linux|X11)/},
            {s:'iOS', r:/(iPhone|iPad|iPod)/},
            {s:'Mac OS X', r:/Mac OS X/},
            {s:'Mac OS', r:/(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},
            {s:'QNX', r:/QNX/},
            {s:'UNIX', r:/UNIX/},
            {s:'BeOS', r:/BeOS/},
            {s:'OS/2', r:/OS\/2/},
            {s:'Search Bot', r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}

        for (var id in clientStrings) {
            var cs = clientStrings[id];
            if (cs.r.test(nAgt)) {
                os = cs.s;

var divMessage=document.getElementById('OSMessage');

divMessage.innerHTML = divMessage.innerHTML + 'Your Computer Operating system is '+os;


After adding this piece of code to the content Editor, you will get the output as similar to the below screen shot.

Here in this example I have Operation system as Windows 7. So outputs will is “Your system Operating System is Windows 7”.

Need Your Help: I want to know whether the service Packs information of Operating system also we can get  using the script that I am not able to achieve. Please help me if anybody has the solution.

Always appreciate your comments.  And yes I got most of the code from

Friday 9 January 2015

“The type is not registered as safe” when trying to add a webpart to a page in SharePoint 2010

Issue Description:

I had a SharePoint web part solution that is created by my Onsite Colleague. I have deployed the same solution in my Local SharePoint Environment and the Web Part added to the solution gallery. When I add the WebPart to the Page it worked perfectly as it was working on my client colleague machine. So no problem at all. Problem started when he has send the solution second time after doing some modification. Again I followed the same Process to deploy the web part solution. Web part was available in web Part Gallery but whenever I try the webpart to the Page it gives Error: “The type is not registered as safe”
For Information I was using VS 2010 to deploy the Farm Solution to the SharePoint 2010 single Machine Environment.


 I have heard this error before and I know the solution to that might be Safe Control Entry is not added properly to web config of SharePoint Web application but it was not that case. Safe Control Entry was properly added. Next I check the assembly Public Key Token which was present in GAC and match with Assembly Key Token present in the Register safe control entry in Web Config of the Web Application. Still I found both the Public Key Token also same. After this I started to take help from Google but most of the Blogs were almost saying the same which I tried initially to solve the Issue.
I Have spent more than 6 Hours to figure out what and where is going wrong, so I am not able to add the Web Part.


Finally I have found the Issue with the Name space of the web part. It was changed from the previous correct Namespace. Once I have change back the same old Namespace it was working fine. So be careful and check the proper Namespace of the Webpart and same Namespace should be registered into the Safe Control of Web Config File. Please Ask me if you still face the issue