SharePoint 2010 development with Visual Studio 2010

This SharePoint 2010 tutorial explains the below things:

  • What exactly happens when we do F5 in Visual Studio 2010 in SharePoint 2010?
  • Shortcut keys in Visual Studio 2010
  • The URL or name of this list instance conflicts with a list instance already on the server in visual studio 2010 in SharePoint
  • Generate strong Name of Class using Visual Studio 2010
  • The project type is not supported by this installation error when creating any SharePoint project in Visual Studio 2010
  • SharePoint 2010 project templates missing in Visual Studio 2010
  • Close SharePoint modal dialog using visual studio 2010

SharePoint 2010 project templates missing in Visual Studio 2010

This SharePoint 2010 tutorial, we will discuss how to solve the issue, SharePoint 2010 project templates missing in visual studio 2010.

Recently in one of the SharePoint front end servers, I have installed visual studio 2010. It has SharePoint 2010 already installed before we installed visual studio 2010. But when we open visual studio 2010 and try to add a new project, we are not able to see the SharePoint related templated in the visual studio.

You can try below solutions which will add SharePoint templates in visual studio 2010.

Close your Visual Studio 2010 if you have opened.

Then Open your visual studio 2010 command prompt (from the menu Start->All Programs -> Microsoft Visual Studio 2010 -> Visual Studio Tools and then click on Visual Studio Command Prompt (2010)) in administrator mode and then run the below command.

devenv.exe /InstallVSTemplates

Now restart your visual studio and now you should be able to see the SharePoint 2010 related templates.

If it did not work, sometimes reinstall or repair works.

Also, check SharePoint 2016 Project Template for Visual Studio 2015.

Or you can download and install VS 2010 SDK or VS 2010 SP1 SDK from the below URL.

What exactly happens when we do F5 in Visual Studio 2010 in SharePoint 2010?

Now, we will see what exactly happens when we do F5 in Visual Studio 2010 in SharePoint 2010? If we do F5 while developing a solution in Visual Studio 2010, the following steps will happen internally.

  • It will first build the project.
  • Then it packages the project into a WSP file.
  • Then in deactivates/uninstall the existing feature
  • Then it retracts or deletes the old WSP file
  • After that, it does an IIS Reset.
  • Then it deploys the new WSP file.
  • It then Activates the feature to the targeted website.
  • Finally, it attaches the debugger.

Shortcut keys in Visual Studio 2010

Below are the shortcut keys in Visual Studio 2010

Ctrl+S                  Save current file
Ctrl+Shift+S     Save all files
Ctrl+Shift+N     Create a new project
Ctrl+O                  Open file
Ctrl+Shift+O     Open project
Ctrl+Shift+A     Add item to project
Esc                  Close menu or dialog
Ctrl+P                  Print
Shift+Alt+Enter     Toggle full-screen mode
Ctrl+F4                  Close current tab
Ctrl+F                  Find and Replace dialog box
F3/Shift+F3     Find next / find previous
Ctrl+H                  Display Replace options on the quick tab
Shift+F12     Find all references for the selected symbol
Ctrl+Shift+F     Find in files
Ctrl+F3/Ctrl+Shift+F3 Find next / find previous in selected text
Alt+F12     Find symbol
Ctrl+D     Put cursor in find/command box of the toolbar. Use ctrl+/ in Visual C#
Shift+Alt+F12  Quick find symbol
Ctrl+G     Goto line number
Ctrl+]     Go to matching brace in a source file
Ctrl+x, Ctrl+c, Ctrl+V     Cut, copy, paste
Ctrl+Shift+V                Pastes an item from the Clipboard
Ctrl+Z     Undo
Ctrl+Y     Redo
Ctrl+W     Select current word
Esc     Cancel Selection
Ctrl+A     Select All
F6     Build solution
Ctrl+Alt+F7     Rebuild solution
Ctrl+Break     Cancel build process
Ctrl+\+E           Show error list
F9                 Toggle breakpoint
Ctrl+B                  Insert new function breakpoint
F5                 Start debugging
F11                Debug / step into
F10 Debug/step over
Shift+F11           Debug / step out
Ctrl+Alt+Q     Show Quickwatch window
Ctrl+Shift+F10     Set current statement to be the next executed
Ctrl+Alt+E     Show Exception dialog box
Ctrl+F11     Toggle between disassembly and user code view
Shift+F5     Stop Debugging
Ctrl+F5     Bypass debugger
Ctrl+Alt+break     Break all executing threads
Ctrl+Alt+S     Open Server explorer window
Ctrl+Shift+L     Open Solution Explorer window
Shift+Esc     Close Find & Replace Window

The URL or name of this list instance conflicts with a list instance already on the server in visual studio 2010 in SharePoint

Now, we will see how to fix error, The URL or name of this list instance conflicts with a list instance already on the server.

When I created the List Instance in visual studio 2010. The first deployment is successful but when again I deploy that solution I got the error message:

“The URL or name of this list instance conflicts with a list instance already on the server. The list instance on the server will be deleted before deploying the new list instance”.

The URL or name of this list instance conflicts with a list instance already on the server sharepoint

First, we select the list definition name and expand that list and select the List instance and now open properties. In the property we able to See Deployment Conflict Resolution. When you then click that than the dropdown list is open and you see there are three options:

  • None: Keep it your existed list with an item (If a list is not there that list will be created).
  • Prompt: Give the error message with Prompt (See in fig 1)
  • Automatic: Automatic deletes the existing list.

By default is Prompt. So if you want to delete the already existed list in the server than Select Automatic. And if you want to keep it your existed list with the item then select None. So the best solution is to keep it as a NONE.

The URL or name of this list instance conflicts with a list instance sharepoint

Generate strong Name of Class using Visual Studio 2010

Now, we will see how to generate the strong name of the class using Visual Studio 2010.

Open visual studio, go to Tools – External Tools. See in fig

generate strong name using Visual Studio 2015

It will look like this. See fig. See in fig

generate strong name using Visual Studio 2013

Now click on Add and give the below details:

  • Title: StrongName
  • Command: Powershell.exe
  • Arguments: command “[System.Reflection.AssemblyName]:: GetAssemblyName(\”$(TargetPath)\”).FullName”

And select Use Output Window. After all this, it will look like below image. And finally, click applies. See in fig

generate strong name using Visual Studio 2010

Now open any .cs class file and go to Tools=>StrongName you will get a strong name of the class.

This is how we can generate the strong name of the class using Visual Studio 2010.

The project type is not supported by this installation

Recently while working with a team where they were trying to develop a SharePoint 2010 visual web part by using Visual Studio 2010, we got the error which says: “The Project type is not supported by this installation”.

It was showing like below:

The project type is not supported by this installation

I tried to check the physical folder, there I do not see any files other than a solution file. So even if I will try to open the solution nothing comes up.

Solution:
I check the Visual Studio version, it was showing something like Visual Studio 2010 Shell.

Then we installed the professional version and we are able to create and deploy a visual web part to the SharePoint 2010 site.

Other solutions people suggest:
There are few other solution people suggest is:

Solution-1:
Try to repair the visual studio which may help.

Solution-2:
Close your visual studio 2010 and then Open the .csproj file in the notepad and then remove the GUIDs presented between <ProjectTypeGuids> </ProjectTypeGuids> tags. This may also solve the issue. In my case, the .csproj was not there, so I can not try this option.

Close SharePoint modal dialog using visual studio 2010

Now, we will see how to close a SharePoint modal dialog box using Visual Studio 2010 in SharePoint 2010.

First we create the application page using visual studio 2010 and map the folder with SharePoint layouts folder and I give the name of that application page WFView.aspx. See in fig

Close SharePoint modal dialog using visual studio 2010

Now in this page I added two buttons. Replace the code in place of <asp:Content ID= “Main”

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<h1>Custom Content Type View Page to approve the workflow activities</h1>
<asp:Button ID="btnApprove" runat="server" Text="Approve" onclick="btnApprove_Click"/>
<asp:Button ID="btnReject" runat="server" Text="Reject" onclick="btnReject_Click"/>
</asp:Content>

Now open the code behind code and add the following method for buttons

protected void btnApprove_Click(object sender, EventArgs e)
{
<!— this is code for closing the model dialog after event is fire –>
Context.Response.Write("<script type=’text/javascript’>window.frameElement.commitPopup();</script>");
Context.Response.Flush();
Context.Response.End();
}

protected void btnReject_Click(object sender, EventArgs e)
{
<!— this is code for closing the model dialog after event is fire –>
Context.Response.Write("<script type=’text/javascript’>window.frameElement.commitPopup();</script>");
Context.Response.Flush();
Context.Response.End();
}

Now save and deploy.

Now when you open the page as model dialog than you able to see your page with two buttons. See in fig.

Close modal dialog using visual studio 2010 sharepoint 2010

Now when you click on Approve or Reject button the form will be close.

Note – If you are not using that code then when you click on the button, your event is fire but the page will be not close.

SharePoint Datetime update is one day off

This is almost certainly a result of your timezone. When a Date Only picker returns a value, it returns a DateTime, where the time component is midnight for the local timezone – e.g. 2012-01-04 00:00:00.

When this value is converted to UTC time, it can become a value for the previous day. For email, if the local time zone for the above datetime is +2, then UTC time would be 2012-01-03 22:00:00.

Naturally, if you simply look at the date part of the date time, this now appears to be an entire day before. I would suggest you start by looking at the date component of the Expiry date – is that offset by your timezone setting?

SharePoint does store all datetimes in UTC time, so it will convert that local datetime to UTC. I’m not sure, off the top of my head, what timezone the datetimes in the AfterProperties are in.

The problem I’m updating a list with a date field (just the date) using the Client object model but when the date is inserted is one day off from the introduced date.

After searching for a long time, it turns out that the “problem” was how SharePoint stores dates. Indeed SharePoint converts dates to UTC … that’s why my comparison was not good!

So when you want to work in code behind with dates, do not forget to convert to UTC!

For this, two methods:
SPTimeZone.UTCToLocalTime et SPTimeZone.LocalTimeToUTC

Another option would be to retrieve the time zone of SharePoint and explicitly convert now in local time by using the .NET Framework when you save the item list as shown below.

//1.Retrieve SharePoint TimeZone
var spTimeZone = context.Web.RegionalSettings.TimeZone;
context.Load (spTimeZone);
context.ExecuteQuery ();

//2.Resolve System.TimeZoneInfo from Microsoft.SharePoint.Client.TimeZone
var fixedTimeZoneName = spTimeZone.Description.Replace("and", "&");
var timeZoneInfo = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(tz => tz.DisplayName == fixedTimeZoneName);

//3.Convert Time
listItem ["DateTime"] = TimeZoneInfo.ConvertTimeFromUtc (dt, TimeZoneInfo);

SPContext class in SharePoint 2010

Now, we will discuss SPContext class in SharePoint 2010/2013.

  • Represents the context of an HTTP request in Microsoft SharePoint Foundation.
  • This class also available in SharePoint Sandboxed solution also.
  • Present in the Assembly Microsoft.SharePoint.dll.
  • This class returns current information about the list, site and also site collection, also you can retrieve the current user name also.

Here are some example of SPContext class:

string userLoginName=SPContext.Current.Web.CurrentUser.LoginName; //This will return current login name.
SPList currentList = SPContext.Current.List; //Give you the current list associated with the context
SPWeb currentWeb = SPContext.Current.Web; //Returns the current site associated with the context
SPSite currentSite = SPContext.Current.Site; //Returns current site collection associated with the context
SPWebApplication currentWebApplication = SPContext.Current.Site.WebApplication; //Returns current web application associated with the context.
SPContext.Current.SiteFeatures //Give you the activated site collection features of the SharePoint context.

You can check more on msdn in this URL.

You may like following SharePoint 2010 tutorials:

This SharePoint tutorial helps us to add SharePoint project templates in visual studio 2010.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SPGuides.com

>