Sharepoint lead is a place where you can read about interesting topics related to sharepoint, and you can also post comments and suggessions.

Thursday, November 27, 2014

Visual studio hangs

My visual studio 2012 became really really slow when editing ascx file. In entire of my solution there was only 1 web part and bunch of other cs and other important files. I noticed when I am editing ascx file it was really really slow and unresponsive after every couple of seconds.

I found that when you have some urls that uses //somescript.path.js instead of http:// or https:// to allow browser to auto resolve protocol, that is happening.

After reading this somewhere on web, I changed my code to use Request.Url.Scheme in order to dynamically choose protocol instead of using // in the starting and problem was resolved.

g.cs - How it works!

I recently found during my deployment that once of my visual web part's ascx content is not updated in the staging environment when I deploy wsp!

So, I started searching for my ascx file in 14 hive but did not find it anywhere. That became really frustrating when I was not able to find ascx file in my local farm's 14 hive as well! I did some google searching for g.cs and most of the results were either complaining about "can not find Initialize control" or they got a blank g.cs file!

Then I went ahead and looked into the source code for the g.cs file and I found that for each of your control in ascx, its actually generating elements. For static content, its concatenating to string variable and for all server controls, its generating code and setting properties. I recall doing same in classic web parts without ascx controls and my question was answered.

So, g.cs file is c# version of your ascx code so that it doesn't have to deploy ascx control in file system but instead works just like a classic web part!

Well, in that case, it should work as sandbox solution as well, right? I did not tried it but ideally yes if your code is following limitations for sandbox solutions.

Now the original problem was:
In our organization we use source control system. Upon pull, I got conflicts and I correctly merged ascx file but not properly merged g.cs file considering its useless and visual studio automatically handles it when I will open project.

But that wasn't true. After doing this, when I publish/deploy my wsp, visual studio will not regenerate that file again on build/publish/deploy. It only generates g.cs file again when you hit save in ascx control. That was the answer of my problem.

So, never ignore ascx.g.cs files in your solution, always make sure you merge g.cs files OR after every conflict you hit save in your ascx to regenerate ascx.g.cs file again! That's what I conclude.

I hope this will be helpful to you all!

iCal - Cancel 1 meeting from recurring meetings

I was working on generating an iCAL invite from a calendar item and was having difficulty deleting once of the event from series.

I found that you have to generate the same ICAL invite that you did for recurring event but there will be two things different
  1. Add Recurrence-ID;Value:DATE=yyyyMMDD (your get the value from SPListItem["ReucurrenceID"])
  2. Change the METHOD in your email and ical content to CANCEL
  3. Increment sequence parameter
Once you adjust your cancel invite with these three changes, your email will show remove from calendar link and clicking on it will only remove the event specified in Recurrence-ID.

Friday, July 25, 2014

Cross site list view web part anywhere in site collection


There are times when you want to display list/library from root level site collection or visa-versa to sub-site but stuck because sharepoint don't provide list view web part that can be shown across sub sites. If you are in same site collection, its possible with the trick I am going to share.

Step 1 - Create a page and drop list view web part there

Create a page in the site/web where you got the list/library and drop the list view web part into that page and save the page.

Step 2 - Export lsit view web part

If you try to see the edit menu for the web part and there is a link called "Export" you can directly export and download the web part.

If you can not see "Export" option in the web part menu, you have to do following:
  • Right click on the web part content heading that shows list/library fields and click on inspect element (IE9+, chrome, firefox and other popular browsers)
  • Once you are ready with web part id, you can use following url to export the web part

Step 3 - Set Web ID

  • Switch to powershell and get guid of the web where the list exists. $w = Get-SPWeb -identity url-of-web;w.ID
  • Open exported .webpart file and find WebID property and set value of the guid you get to the value in WebId node in web part file.

Step 4 - Upload it to web part gallery

  • Go to site settings > Galleries > web part galleries
  • click on upload and upload your web part file here and set title, group and description of the web part

Step 5 - Finished

  • Go to anywhere in your site collection and add the web part. It will show you the list view web part that you uploaded in specific group.


I tested this with list/libraries having html as default view and rendering of the list view web part works. There are lots of functions associated with the list/library that can be performed from ribbon that I have not tested. Please make sure you consider that while using this trick.

Wednesday, April 23, 2014

ascx.g.cs Empty

In Visual Studio 2012, when you are working with a visual web part, your user control's ascx.g.cs file becomes empty. So you get an error "The name ‘InitializeControl’ does not exist in the current context".

Root cause:
This is reported as a bug in visual studio 2012 and it generally happens when your server side mark up is having issues. This ONLY happens when you are editing your ascx file.

Suggested Solution:
You can try following:
Short way:

  • try to undo some of the last changes in ascx file.
  • Create copy of ascx file and revert it from source control. Rename g.cs to g.txt and switch to ascx and hit save. That will generate another g.cs with correct content

Long way:

  • Please check the @Register declarations against the TagPrefix and TagName that you are using.
  •  Try to comment out all controls in ascx and save it. That will generate ascx.g.cs along with content again. Now start un-commenting the controls one by one.
  • In worst cases, after trying lots of things people also switch to new web part and migrate useful code from the problematic web part step by step to resolve the error. 

Wednesday, April 16, 2014

Keep it up

Sometime back when Rajasthan Royals won the first IPL, I was working with Virtual Lifestyle Pvt Ltd, and CEO Vikas Sabnani explained how Rajasthan Royals being a cheapest team, won the game. Here are three things that he noticed that applies to every team and team players of the world.

  1. Focus on Quality
    Being an important member of the team, if you do so, you are not achieving for yourself and team at the same time. Focusing on quality is as easy as you read it.
  2. Be Proactive
    Here is what the definition says: "creating or controlling a situation rather than just responding to it after it has happened." There are great example of proactive work but in our software world, detecting & fixing or implementing stuff ahead of time with the best suited and most efficient way
  3. Have fun!
    Having fun with what you do is also as important as the other two.
If you are doing it all three together, you are doing it right! If not, what are you waiting for?