Scenario:
I have been building and deploying my Sharepoint Sequential Workflow with no issues.
Now I started to get following error: output details are as below
Successfully installed this assembly into the global assembly cache: CustomWF.dll.
Successfully restarted Internet Information Services (IIS).
Successfully copied workflow.xml to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\CustomWF\workflow.xml.
Successfully copied feature.xml to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\CustomWF\feature.xml.
Successfully installed the workflow template to Microsoft Office SharePoint Server.
Failed to associate this workflow template with a Microsoft Office SharePoint list. Object reference not set to an instance of an object.
Failed to deploy the workflow template to Microsoft Office SharePoint Server.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========
Solution:
While I was not to totally find the real cause of the issue but did a workaround to move forward.
Steps:
1. Created folder structure 12\TEMPLATE\FEATURES\CustomWF
2. Moved the feature.xml inside the folder
3. Moved the element.xml inside the folder
4. Build WSP using WSPBuilder
Article:
Open issue
Tuesday, July 26, 2011
Monday, June 7, 2010
Scenario:
I was trying new features of Silverlight 4 and got following error opening the project
The imported project "C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Silverlight.CSharp.targets" was not found.
Confirm that the path in the declaration is correct, and that the file exists on disk.
Solution:
Reason is simple Visual Studio 2010 is missing the support for Silverlight 4, so you will need Silverlight 4 for VS 2010 to be able to make it work
1. Google for 'Web Installer 2.0'
2. Download and install it.
3. Now launch the Web Installer and look for Silverlight 4 add-on for Visual Studio 2010.
4. Select it and install it.
Just in case Web Installer is not able to install the component or you want to download the Silverlight 4 tools for VS 2010. You can get it from this here
Monday, May 31, 2010
Scenario:
Sharepoint is relatively big product and lot of small small things can make the developers productive. Here's a small tip to easily generate the entities for LINQ to SharePoint.
Steps:
1. Look for SPMetal locally.
2. Open Visual Studio
3. Go to Tools > External Tools > Add a new tool with below settings
Setting:
Title : SPMetalNow just go to Tools > SPMetal , once it runs you will see a new file in the project directory , include it in the project and use it.
Command : C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Bin\SPMetal.exe <-- ( This is default location where SPMetal is installed )
Arguments : /web:http://intranet.contoso.com /namespace:SKN.Samples /code:TeamSiteDataContext.cs
Use Output Window : Checked
Output as Unicode : Unchecked
Initial Directory : $(ProjectDir)
Recommended:
SPMetal generates code for all the list / libraries and so its better to start with Blank Site and add required list / libraries to it and then run SPMetal.
Article:
How to: Use SPMetal , SPMetal
Sunday, February 7, 2010
Scenario:
I often use Solution Generator and have found many workaround to fit this tool to my needs. Recently I found 2 strange behavior, when I reverse engineer a site definition which has some list view web parts on one of the pages.
1. These web parts had toolbar set to Standard toolbar, it was not respecting the Toolbar type selected.
2. I have added some extra columns to the views, not getting the match when deploying the generated solution.
Solution:
When I took a closer look at the CAML which got generated for the Webpart it had the right Toolbar value and columns in ViewFields.
Actually issue was the BaseViewID attribute for the
Setting BaseViewID to Zero solved the issue.
Other important thing to use Solution Generator:
1. Always create a brand new site from out of box templates to generate a site definition
2. For ListView web parts, don't switch the View from the drop even if it matches your requirement.Always edit the Current View > Edit this View option.
Tuesday, October 13, 2009
Scenario:
Of the common issues with Content Types updates in production is change in field types. OOTB there are few supported field type change but some time not really give you the correct results.
So as a workaround you can add a new field to content type and copy over the data from the old field to the new one.
Along the same lines one of my colleague wanted to copy data across Lookup Column Fields. Source field was a Single Select field and destination was Multi-Select field and there were 100s of sub sites to update.
Solution:
Small utility function did the trick.
Code:
public static void CopyValues()
{
string siteCollectionUrl = "http://localhost";
string sourceFieldDisplayName = "SourceFieldDisplayName";
string destinationFieldDisplayName = "DestinationFieldDisplayName";
using (SPSite site = new SPSite(siteCollectionUrl))
{
foreach (SPWeb web in site.AllWebs)
{
foreach (SPList list in web.Lists)
{
try
{
if (null != list.Fields[sourceFieldDisplayName] && null != list.Fields[destinationFieldDisplayName])
{
string sourceFieldInternalName = list.Fields[sourceFieldDisplayName].InternalName;
string destinationFieldInternalName = list.Fields[destinationFieldDisplayName].InternalName;
foreach (SPListItem item in list.Items)
{
SPFieldLookupValue sourcevalue = new SPFieldLookupValue(item[sourceFieldInternalName].ToString());
SPFieldLookupValueCollection destinationValueCollection = new SPFieldLookupValueCollection();
destinationValueCollection.Add(sourcevalue);
item[destinationFieldInternalName] = destinationValueCollection;
item.Update();
}
list.Update();
}
}
catch
{
}
}
web.Dispose();
}
}
}
Wednesday, July 1, 2009
Scenario:
I keep looking for ways to provide tools to easily discover common issues so that automatically code can comply with best practice.
You can bing about Best Practice for Code Analysis and there is a utility which can help you to find some of the common problems. You can download it from here -- > Download MSI
Solution:
As I said tools should be easy to use , so here a small tip to make FxCop part of you every Visual Studio project.
Steps:
1. Install FxCop 1.35 locally.
2. Open Visual Studio
3. Go to Tools > External Tools > Add a new tool with below settings
Setting:
Now just go to Tools > FxCopCmd and you can see the report in your output window.
Title : FxCopCmd
Path : C:\Program Files\Microsoft FxCop 1.35\FxCopCmd.exe ( This is default location where FxCop is installed, so if u have choose a different location while installing it, make sure to point it to right spot. )
Arguments : /c /searchgac /f:$(BinDir)$(TargetName)$(TargetExt)
Use Output Window : Checked
Saturday, June 27, 2009
Scenario:
While installing an endpoint for WCF Host service, we wanted to look for a port which is not being used by any other program for communication, to avoid any issues. Also we had many other WCF Host services in pipeline, so we wanted a standard way of choosing an unused port on our servers.
Solution:
PortQry was the solution. There is a command line version and a UI based version available for download from Microsoft.
PortQryV2.exe is a command-line utility that you can use to help troubleshoot TCP/IP connectivity issues. Portqry.exe runs on Windows 2000-based computers.The utility reports the port status of TCP and UDP ports on a computer you choose.
Download Command Line Utility
Download UI Based Utility
Examples :
The following command tries to resolve "reskit.com" to an IP address and then queries TCP port 25 on the corresponding host:
portqry -n reskit.com -p tcp -e 25The following command tries to resolve "169.254.0.11" to a host name and then queries TCP ports 143,110, and 25 (in that order) on the host that you selected. This command also creates a log file (Portqry.log) that contains a log of the command that you ran and its output.
portqry -n 169.254.0.11 -p tcp -o 143,110,25 -l portqry.logThe following command tries to resolve my_server to an IP address and then queries the specified range of UDP ports (135-139) in sequential order on the corresponding host. This command also creates a log file (my_server.txt) that contains a log of the command that you ran and its output.
portqry -n my_server -p udp -r 135:139 -l my_server.txtArticle:
KB Article
Sunday, June 21, 2009
Scenario:
Sharepoint is relatively new for lot of developers and its hard to just guide them on something by saying its best practice. I believe in finding ways to provide tools to easily discover common issues so that automatically code can comply with best practice.
You can bing about Best Practice for Disposing objects and there is a utility which can help you to find some of the common problems. You can download it from here -- > Download MSI
Solution:
As I said tools should be easy to use , so here a small tip to make SPDisposeCheck part of you every project.
Steps:
1. Install SPDisposeCheck locally.
2. Open Visual Studio
3. Go to Tools > External Tools > Add a new tool with below settings
Setting:
Title : SPDisposeCheckNow just go to Tools > SPDisposeCheck and you can see the report in your output window.
Command : C:\Program Files\Microsoft\SharePoint Dispose Check\SPDisposeCheck.exe <-- ( This is default location where SPDisposeCheck is installed )
Arguments : "$(BinDir)$(TargetName)$(TargetExt)" -debug
Use Output Window : Checked
Article:
Best practices
Friday, June 19, 2009
Scenario:
We wanted to test access to our service for kerberose.
Solution:
Small console application to test if i can reach the resource. Make sure you are testing a secured resource , and the username used to make the call has SPN created.
Code:
using System;Follow me on Twitter
using System.Collections;
using System.IO;
using System.Net;
using System.Text;
namespace Training {
class Program {
public static void Main(string[] args) {
Console.WriteLine("Kerberose Test Application");
string sUrl = @"http://localhost/getDoc.aspx?id=66";
try
{
//Display what Authentication modules are registered
DisplayRegisteredModules();
// Unregister the standard Basic, NTLM and Negotiate and Digest modules, leaving only Kerberos
// AuthenticationManager.Unregister("Basic");
// AuthenticationManager.Unregister("NTLM");
// AuthenticationManager.Unregister("Negotiate");
// AuthenticationManager.Unregister("Digest");
AuthenticationManager.Unregister("Kerberos");
//Display what Authentication modules are left registered
DisplayRegisteredModules();
// Prepare the web page we will be asking for
var request = (HttpWebRequest)WebRequest.Create(sUrl);
request.UserAgent = "MOSSPH";
request.Proxy = null;
Console.WriteLine();
Console.WriteLine(string.Format("Trying to access :{0}",sUrl));
// TODO. Establish your own security context.
//request.Credentials = CredentialCache.DefaultCredentials;
request.Credentials = new NetworkCredential("username", "password", "domain");
//request.Credentials = new NetworkCredential(args[0], args[1], args[2]);
//CredentialCache wrCache = new CredentialCache();
//wrCache.Add(new Uri(sUrl), "Kerberos", new NetworkCredential("username", "password", "domain"));
//request.Credentials = wrCache;
//CredentialCache wrCache = new CredentialCache();
//wrCache.Add(new Uri(sUrl), "Negotiate", new NetworkCredential("username", "password", "domain"));
//request.Credentials = wrCache;
var response = (HttpWebResponse)request.GetResponse();
// we will read data via the response stream
Console.WriteLine(response.ContentType.ToString());
Console.WriteLine((ulong)response.ContentLength);
Console.WriteLine(response.StatusDescription.ToString());
Stream stream = response.GetResponseStream();
DisplayPageContent(stream);
// Displays all the headers present in the response received from the URI.
Console.WriteLine("\r\nThe following headers were received in the response:");
// Displays each header and it's key associated with the response.
for (int i = 0; i < response.Headers.Count; ++i)
Console.WriteLine("\nHeader Name:{0}, Value :{1}", response.Headers.Keys[i], response.Headers[i]);
Console.WriteLine("\nHeader Name:{0}, Value :{1}", response.ContentType.ToUpper(), response.ContentLength.ToString());
// Releases the resources of the response.
response.Close();
}
catch (Exception ex) {
Console.Write("Error occured:" + ex);
}
finally {
Console.Read();
}
}
private static void DisplayRegisteredModules() {
IEnumerator registeredModules = AuthenticationManager.RegisteredModules;
Console.WriteLine("\r\nThe following authentication modules are now registered with the system:");
while (registeredModules.MoveNext())
{
Console.WriteLine("\r \n Module : {0}", registeredModules.Current);
var currentAuthenticationModule = (IAuthenticationModule)registeredModules.Current;
Console.WriteLine("\t CanPreAuthenticate : {0}", currentAuthenticationModule.CanPreAuthenticate);
}
}
// The DisplayPageContent method display the content of the selected page.
private static void DisplayPageContent(Stream receiveStream) {
// Define the byte array to temporarily hold the current read bytes.
var read = new Byte[512];
// Read the first 512 bytes.
int bytes = receiveStream.Read(read, 0, 512);
Console.WriteLine("\r\nPage Content...\r\n" + Encoding.ASCII.GetString(read, 0, bytes));
}
}
}
Tuesday, June 9, 2009
Scenario:
During my sharepoint development I need to generate new Guid's all the time
Solution:
Visual Studio does provide a GuidGen.exe tool, but its kinda multi-step process.
After some research I got the solution - MACRO , my old pal :-)
Step:
1. VS > Macros > Macro Explorer
2. Create a new Module and paste the below Macro code into it
3. Go to VS > Tools > Options
4. Create a key board short cut of your choice , I used Ctrl+Alt+G as shown below
Macro Code:
Sub Create_GUIDArticle:
Dim sel As TextSelection
sel = DTE.ActiveDocument.Selection
sel.Text = System.Guid.NewGuid.ToString("D").ToLower()
End Sub
Generating-guids-in-the-visual-studio-ide , Create online guid
Follow on Twitter
Friday, June 5, 2009
Project Description:
This utility is great for merging the web.config files for sharepoint based web applications.
Limitations:
-- This will only work for SharePoint web applications ( WSS and MOSS )
-- This need to be executed on all the Web Front ends ( I know painful , but SPWebConfigModification class is buggy and unreliable ). I have tested it on Single Server Farm so far
-- This utility can be run only one time per web application
-- To run it again on same web application [ no recommended for Production ] , all the GUIDs for the merge file need to be renewed. Check the sample merge xml file
Advantage:
-- This can merge many files from the mergefile location
Download
Usage
1. Download the sample merge file and change it according to requirement
2. Download SPMergeWebConfig.exe and run the following command with proper parameters
SPMergeWebConfig.exe -file 'C:\Inetpub\wwwroot\wss\VirtualDirectories\80\' -mergefile 'C:\Inetpub\wwwroot\wss\VirtualDirectories\80\'
Note : -file parameter takes a location value where you web.config file reside
-mergefile paramter takes a location value for the merge file you downloaded , utility can accept more than one files with the file name pattern as +webconfig.*.xml+
Follow on Twitter
Friday, May 29, 2009
FxCop is a code analysis tool that checks .NET managed code assemblies for conformance to the Microsoft .NET Framework Design Guidelines. It uses MSIL parsing, and callgraph analysis to inspect assemblies for more than 200 defects in the following areas:
Library design
Globalization
Naming conventions Performance
Interoperability and portability
Security
Usage
FxCop includes both GUI and command line versions of the tool and supports analyzing .NET 1.x, .NET 2.0 and .NET 3.x components.Release
FxCop is intended for class library developers. However, anyone creating applications that should comply with the .NET Framework best practices will benefit. FxCop is also useful as an educational tool for people who are new to the .NET Framework or who are unfamiliar with the .NET Framework Design Guidelines.
FxCop is designed to be fully integrated into the software development cycle and is distributed as both a fully featured application that has a graphical user interface (FxCop.exe) for interactive work, and a command-line tool (FxCopCmd.exe) suited for use as part of automated build processes or integrated with Microsoft Visual Studio® .NET as an external tool.
Download fxCop
CAT.NET is command line tool that helps you identify security flaws within a managed code (C#, Visual Basic .NET, J#) application you are developing. It does so by scanning the binary and/or assembly of the application, and tracing the data flow among its statements, methods, and assemblies. This includes indirect data types such as property assignments and instance tainting operations. The engine works by reading the target assembly and all reference assemblies used in the application -- module-by-module -- and then analyzing all of the methods contained within each. It finally displays the issues its finds in a list that you can use to jump directly to the places in your application's source code where those issues were found.
The following rules are currently support by this version of the tool.
- Cross Site Scripting
- SQL Injection
- Process Command Injection
- File Canonicalization
- Exception Information
- LDAP Injection
- XPATH Injection
- Redirection to User Controlled Site.
Download
Friday, April 10, 2009
Scenario:
While testing my WCF service using netTCP binding, I got the following error.
Error:Unhandled Exception: System.ServiceModel.AddressAlreadyInUseException: There is already a listener on IP endpoint 0.0.0.0:9000. Make sure that you are not trying to use this endpoint multiple times in your application and that there are no other applications listening on this endpoint. ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted
Reason:
NetTcp Port Sharing is a Windows Communication Foundation (WCF) feature that is similar to IIS and allows multiple network applications to share a single port. The NetTcp Port Sharing Service accepts connections using the net.tcp protocol and forwards messages based on their destination address.But NetTcp Port Sharing Service is not enabled by default.
Solution:
1. You can also use TCPView to check what process that is holding the port open.
2. Check using following command
netstat -a | find "portno"
3. Try restarting the service or server
4. Try configuring the service on different port number
5. You can try enabling port sharing ( require NetTcp Port Sharing Service running)
Code:
Article:
<system.serviceModel>
<bindings>
<netTcpBinding name="customBinding"
portSharingEnabled="true" />
<services>
<service name="MyService">
<endpoint address="net.tcp://localhost/MyService"
binding="netTcpBinding"
contract="IMyService"
bindingConfiguration="customBinding" />
</service>
</services>
</system.serviceModel>
TCP View
Saturday, January 17, 2009
Scenario:
I was trying Visual Studio Extension for Workflow and go the following error while creating a new workflow. I added a new project , it poped-up a screen asking for the Url to the site , I want to attach the workflow... now the thing is it already had a default value 'http://spvm/docs' and if i go ahead with the default value, it gave me error saying -- Check for the Url to the site , Administrator may need to add a new request Url mapping to the intended application
Solution:
Basically its very simple , wizard expect Url to the site and not the document library or list you want to attach workflow. So I changed the Url from
http://spvm/docs >> http://spvm
and it worked.
Wednesday, December 10, 2008
Scenario:
Sharepoint require most of the assemblies to be strongly named and referenced using 4 part name of the assembly.
Solution:
You can use sn.exe utility to get the public token key for your assembly
Code:
Article:
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\sn.exe" -T MyAssembly.dll
or
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe" -T MyAssembly.dll
http://grounding.co.za/blogs/brett/archive/2007/11/02/determine-the-public-key-token-for-assembly.aspx
Friday, October 24, 2008
Links:
CAMLViewer
CAML Viewer
CAML Builder
http://weblogs.asp.net/jan/archive/2008/05/28/new-version-of-the-caml-query-builder-tool.aspx
Internet Developer ToolBar
http://www.microsoft.com/downloads/details.aspx?familyid=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en
FireBug
https://addons.mozilla.org/en-US/firefox/addon/1843
Google Chrome( comes with document inspector )
Chrome
WSPBuilder
http://www.codeplex.com/wspbuilder
FAR
http://www.rarlab.com/
BDCMetaMan
http://www.lightningtools.com/default.aspx
Application Pool Recycle and Warmup
http://www.harbar.net/articles/APM.aspx
SPDisposeCheck
http://code.msdn.microsoft.com/SPDisposeCheck
Some more...
http://blog.thekid.me.uk/archive/2008/09/29/my-current-sharepoint-development-toolkit.aspx
http://www.sharepointdevwiki.com/display/public/Other+SharePoint+Development+Tools
http://blogs.tamtam.nl/mart/SharePointToolsGaloreV3.aspx
System Essential Tools
Screen Capture
Mercer Tool
Search Files
Grep for Windows
Wednesday, September 24, 2008
SharePoint Manager 2007
The SharePoint Manager 2007 is a SharePoint object model explorer. It enables you to browse every site on the local farm and view every property. It also enables you to change the properties (at your own risk). This is a very powerfull tool for developers that like to know what the SharePoint holds of secrets.
http://www.codeplex.com/spm
Microsoft SharePoint Monitoring Kit download
http://www.microsoft.com/downloads/details.aspx?FamilyId=E4600FD9-F53D-4DED-88BF-6BB1932794F9&displaylang=en
Imtech Fields Explorer
Imtech Fields Explorer is a tool that can help you during the development process while working with fields. The tool allows you to explore properties of the fields contained within the (Site Collection) Content Types and Lists.
http://www.sharepointblogs.com/tmt/archive/2007/08/24/imtech-fields-explorer.aspx
Friday, August 22, 2008
Make sure Environment variable PATH is set for stsadm.exe
How to use it
1. Build the Visual Studio Project you got from SharePoint Solution Generator
2. Download WSPBuilder from http://www.codeplex.com/wspbuilder
3. Extract all the file next to Visual Studio Project file.
4. Copy the below script into a command line batch file next to the Visual Studio Project file.
Script:
rmdir 12 /Q /S
rmdir GAC /Q /S
set /P solutionname="Enter solution name :"
xcopy bin\debug\solution\*.dll GAC\*.* /S
xcopy bin\debug\solution\1033\xml\*.* 12\TEMPLATE\1033\xml\*.* /S
xcopy bin\debug\solution\%solutionname%\xml\*.* 12\TEMPLATE\SiteTemplates\%solutionname%\xml\*.* /S
xcopy bin\debug\solution\*.* 12\TEMPLATE\FEATURES\*.* /S
del 12\TEMPLATE\FEATURES\*.dll
del 12\TEMPLATE\FEATURES\*.xml
rmdir 12\TEMPLATE\FEATURES\%solutionname% /Q /S
rmdir 12\TEMPLATE\FEATURES\1033\ /Q /S
pause
5. Run the following command line
set /P solutionname="Enter solution name :"
stsadm -o retractsolution -name %solutionname%.wsp -allcontenturls -immediate
stsadm -o execadmsvcjobs
stsadm -o deletesolution -name %solutionname%.wsp
del *.wsp
del solutionid.txt
wspbuilder
ren Buildx86.wsp %solutionname%.wsp
stsadm -o addsolution -filename %solutionname%.wsp
stsadm -o deploysolution -name %solutionname%.wsp -allowGacDeployment -allcontenturls -immediate
stsadm -o execadmsvcjobs