Monday, April 1, 2013

SharePoint-13 Multilingual for visual webparts

I had a requirement to create a multilingual visual webpart.The webpart has to be displayed in the language which is described by the browser.

Here is the way to achieve it in sharepoint 13 using the VS12

1)Create a empty sharepoint 13 solution Farm solution .
2) Add a sharepoin 13 project into it .
3)Add a mapped foder "Resources" to the project .
4)Now you gonna add three resources one for english "testMutliLing.en-US.resx" and one for german
    "testMutliLing.de-DE.resx" and one default  "testMutliLing.resx into the mapped folder.
5)In the designer of resource file add the key and value for both english and german resource file .

6)Now open the ascx file and add "label"
7)In the page load event add the following code

int id=1033;
//to get the default broweser language either "en-US" or "de-DE" etc etc


string a = HttpContext.Current.Request.UserLanguages[0].ToString();
if (a.Contains("en-US")){
id = 1033;
}

else{
id = 1031;
}
//german =1031 //english =1033
Label.Text =
SPUtility.GetLocalizedString("$Resources:testMutliLing,String1", "testMutliLing",(uint)id);
}


The en-Us is equal to 1033 you get the different language codes for different languages if you browse for it in internet.

or you can even use

Label.Text = SPUtility.GetLocalizedString("$Resources:testMutliLing,String1", "testMutliLing",(uint)CultureInfo.CurrentUICulture.LCID);


Deploy the solution add the webpart to the page .

It shows the english version picking the value for "String1"  from english resource file.

to check for german .In IE goto internet options-->Languages-->add german de-DE and make it as default language by moving it to the top .say ok and refresh the page

Now the text for Lable is picked by "String1"  from the german resource file.


Also if you want to have multilingual markups you can use as below

<asp:Label ID="lbltest" runat="server" Text="<%$Resources:testMutliLing, String1; %>"></asp:Label>

Friday, March 29, 2013

Get Browser default Language-C#

To find the browser's default language through C# you can use the below code


string [] arrayVariable = HttpContext.Current.Request.UserLanguages;

It returns an array .Since the browser might be having more than one language as preferences .
To get the default preference just pick the first entry of the array

string defaultLangauage = a[0].ToString();

Tuesday, March 19, 2013

The Server was unable to save the form at this time. Please try again in SharePoint 13

I was working on Sharepoint 13 standalone server and suddenly found this error

"The Server was unable to save the form at this time. Please try again."

 

 

I was working on a simple list to add the data into it . The error was not allowing me to add the data into the simple share point list .Searching on internet I came to know that restarting the "Search Host Controller Service" would solve the issue .The ideology was it was eating lot of RAM and so it has to be restarted .But since I knew this issue, in our server "Search Host Controller Service" was already disabled long back ,since we were not working on search .

                    But some how i had to solve this issue since my share point 13 server was taking in any items.

So I decided to give a try and started "Search Host Controller Service" luckily it worked and I was able to add items to any list in the web application .

But I haven't still figured it out why it worked .In my case the service was already disabled and it was not using RAM ,So there is no point in saying restarting the service provided the much needed memory space .But it still worked :(

To restart "Search Host Controller Service" run the services.msc as Admin and start or restart the service.Hope it works for other tooo :)

Friday, February 8, 2013

Query filter webpart in Sharepoint 2010

A demo on how to use the Query filter webpart of Sharepoint 2010.

The "Filter" feature of Sharepoint 2010 is available to you only when you activate the

SharePoint Server Enterprise Site Collection features

which is available only with the Enterprise version installation .

It is used mostly in the requirements mentioned below

  • You have a home page where there are number of links, on click of this it should redirect to new page where the data is displayed based on the option which is clicked in the home page

Process followed to achieve this requiremenst are
1)Create home page and add a content editor webparts
2)Add few anchor tags redirecting to the next page which we will be customizing
3)In the new page Edit Page -->Add a list view webpart also a Query filter webpart.
4)Now in the Page edit mode itself .Click on the edit webpart option of Query filter webpart
Now Add a Paramater say "parm" in the paramater name option .
You can try other oprtions in the menu too ,but I am gonna demo only the simple one
5)Now in the edit mode of page ,Click on the drop down option of  list view webpart which is found on the top right corner of each webpart
6)Select Connections-->Get filter value from -->Select the Query filter option
7)A pop up menu opens Select the field which you want to filter by the "parm" click finish 
8)Now go to the home page edit those anchor tags created in step 2 add query string like 
Eg : testsite/SitePages/DisplayQueryFilter?parm=1


So when to click the anchor tag the page is redirect to say DisplayQueryFilter with query string as "parm=1" for first tag
Now since we have set the paramter name as "parm" in Queryfilter webpart it pulls the value as 1 for above mentioned tag.

This value "1" is used to filter the list below since we set up a connection between the two webparts.



Friday, February 1, 2013

Modal Popup in Sharepoint by javascript

Most come requirement in Sharepoint custom developemt is to have a popup .This can be achieved by using the Modal PopUp .Below is the code script which gives us popup in sharepoint


<script type=”text/javascript”>

function OpenDialog(URL) {
     var options = SP.UI.$create_DialogOptions();
     options.url = URL;
     options.width = 600;
     options.height = 400;
     SP.UI.ModalDialog.showModalDialog(options);
}

</script>

<a href=”javascript:OpenDialog(‘URL of the page to be displayed here’)”>Link</a>


You can use this script in a .js file reference it anywhere in the sharepoint site and you should be able to call the function .