Welcome

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

Introduction

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
http://root-site-url/_vti_bin/exportwp.aspx?pageurl=page-url&guidstring=web-part-guid

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.

Limitations:

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.