Wednesday, 25 August 2010

Infopath form cannot save the following form - Form is Read Only

I have created the infopath project in Visual Studio and deploying into SharePoint environment. After some days, I got to change the infopath form to match the new requirement and redeploy to the SharePoint environment. I have opened the Visual Studio and spent half an hour to edit all the changes and tried to save the form. But, while saving it was started giving me the alert message that "The infopath form cannot save the following form: Template Name is ready only." I did not understand and check all file properties of the manifest.xsf and unchecked the checkbox read only. Still it was giving me the same error message. The error message was completely confused me and no any other clue. So, started searching in internet for the solution and after searched about an hour, found the information. If you have opened the infopath form, then close it. [No other way, you will lose all changes you have made.]

Resolution:
  1. Open the manifest.xsf in notepad.
  2. PublishUrl: Search for "publishurl". I believe, this pointed to the old location other than what actual the form is submitted to. Make it empty [No problem].
  3. runtimeCompatibilityURL: in the notepad, search again for "runtimeCompatibilityURL". Now change its value to "http://sharepointserver/_vti_bin/FormsServices.asmx". 
  4. If you are using the source control like VSS, Source vault, TFS or whatever then you have to do below things.
  • Open Visual Studio and checkout all the files in the Infopath Form Template folder.
  • Once all checked out, then close the Visual Studio and reopen.
    Note: replace sharepointserver in above url with your sharepoint server name.

    Check for more information here. MSDN
    That's it. Now, you have to reopen the file and do whatever changes you have to do. Enjoy.

    Monday, 23 August 2010

    How to get the files from GAC in Windows

    This is what I think about since I started working on Windows. I don't know how to see the Windows GAC files and get them for other use. For example, sometimes I deploy the files to GAC location and then want to move the same dll to some other server. But, as usual, the original files missed from the file system. The only location I can get them is GAC. But, don't know how to get the files from GAC. This is a big question and resolved my my colleague Phani recently. I was surprised and felt very happy after the resolution he found and now I am utilizing it very efficiently.
    There is a command available in Windows for doing the task. "subst".

    The command will create a virtual folder of all GAC files to a separate drive. Below is the syntax:
    subst Z: C:\windows\Assembly
    When you go to the my computer you will find a new drive under the regular drives. Just go inside and you can see all the GAC files. The folder GAC_MSIL is what your all files reside in. Copy the dll's you needed and paste them in some safe location for backup.

    To remove the Z drive from machine, then use below command.
    subst Z: /D
    All credits goes to Phani and take a look at this post from him for more information. Enjoy some nice tips and rare findings from the blog.

    Sunday, 22 August 2010

    Check drop down list contains a value in c#

    This is again a very simple post and want to share. I have seen many people write good coding, but, sometimes they don't pick efficient way to do somethings. When we do code reviews we can identify some code parts are very simple to implement but they implement it in complex way, want to correct them. A simple scenario is, how to check a drop down contains a value. Some people are looping through all items and finding the item exists or not. Some people are doing some complex logic etc. But, below is what I believe the good and simple way of finding a value is in drop down list of items.
    if (ddlUserType.Items.FindByValue("someValue") != null)  
    {
    ddlUserType.SelectedValue = "someValue";
    }
    Do you think, is there any efficient way of doing this?

    bind Enum to drop down list in ASP.NET

    This the question asked by so many people around me and I also faced issues couple of times of my early stages of learning.This is simple but, how to get value and names as a collection and bind to drop down list is a bit difficult. Below is the simple logic to read all enums and create a list item and bind to drop down list. [There are many ways to get this done, but I believe below is the best way.]
    foreach (UserType ut in Enum.GetValues(typeof(UserType)))
    {
    ListItem item = new ListItem(Enum.GetName(typeof(UserType), ut), ((int)ut).ToString("D"));
    ddlUserType.Items.Add(item);
    }
    I think, you like this post. Let me know if you have any issues.

    Thursday, 19 August 2010

    Know the site template used for the SharePoint site

    Hello all, Hope all are doing fine. I believe this is very rarely needed post that we need to know what site template [Publishing site, workspace, meeting workspace, team portal etc..] was used for a particular SharePoint site. From the UI [means by navigating to SharePoint site through browser] we can't identify this. So, we need to follow either of the steps given below to identify the template used for a specific site.
    1. First option is, this is my recommended choice and very easy too. By using SharePoint Manager tool [available for both 2010 and 2007.] Download it for free from Codeplex and install it. Now, open the SharePoint Manager and connect to the SharePoint site collection. When you click on a specific SharePoint site, on the right side it will show you all the properties available in the SP object model for that site. In it find for TemplateID and check the value showing there. That's it. What is TemplateID and how to know template name from it? Navigate to end of this post for TemplateID to Name mapping.
    2. Second option is, if there is no way to install SharePoint manager or if any other problems, then save the current site as site template[.STP extension]. Now, save it to disk somewhere. Now, navigate to that location and rename the file to .CAB extension. Extract the CAB file and find the manifest.xml file. Now, in the file check for the TemplateID string and get the value. Navigate to end of this post for the TemplateID to Name mapping.
    3. From the SP Object Model: Through managed code we can identify this very easily with below code.
      using (SPWeb web = site.OpenWeb("/"))
      {
      string templateID = web.WebTemplateId.ToString();
    4. Using STSADM.EXE: It needs high level permissions. Means the user should be an administrator on the server. Below is the command we need to use for knowing the site template.
      stsadm.exe -o enumallwebs -database [content database name]
    5. From Sql Server: Sql server has all the information about SharePoint. So, if you have access to database then login to the sql server management studio and execute below query on the content database of the application.
      SELECT Title, WebTemplate FROM dbo.Webs WHERE Title='Test Publishing Site'
    Choose one option which is useful or easy for you and identify the correct template.

    Site template ID to Name mapping:
    0 - GLOBAL (SetupPath=global) - "Global template"
    1 - STS - "windows SharePoint Services Site", "Team Site", "Blank Site", "Document Workspace"
    2 - MPS - "Basic Meeting Workspace", "Blank Meeting Workspace", "Decision Meeting Workspace", "Social Meeting Workspace", "Multipage Meeting Workspace"
    3 - CENTRALADMIN - "Central Admin Site"
    4 - WIKI - "Wiki Site"
    7 - BDR - "Document Center"
    9 - BLOG - "Blog"
    20 - SPS (OBSOLETE) - "SharePoint Portal Server Site"
    21 - SPSPERS - "SharePoint Portal Server Personal Space"
    22 - SPSMSITE - "Personalization Site"
    30 - SPSTOC (OBSOLETE) - "Contents area Template"
    31 - SPSTOPIC (OBSOLETE) - "Topic area template"
    32 - SPSNEWS (OBSOLETE) - "News area template"
    33 - SPSNHOME (SubWebOnly) - "News Home template"
    34 - SPSSITES - "Site Directory area template"
    36 - SPSCOMMU (OBSOLETE) - "Community area template"
    38 - SPSREPORTCENTER - "Report Center Site"
    39 - CMSPUBLISHING (SetupPath=SiteTemplates\PUBLISHING) - "Publishing and Team Collaboration Site"
    40 - OSRV (SetupPath=SiteTemplates\OSRV) - "Shared Services Administration Site"
    47 - SPSPORTAL - "Corporate Intranet Site"
    50 - SRCHCEN - "Search Center"
    51 - PROFILES - "Profiles"
    52 - BLANKINTERNETCONTAINER - "Internet Presence Web Site"
    53 - BLANKINTERNET - "Publishing Site", "Press Releases Site", "Publishing Site"
    54 - SPSMSITEHOST - "My Site Host"
    90 - SRCHCENTERLITE (SetupPath=SiteTemplates\SRCHCENTERLITE) - "Search Center Lite"
    6221 - PWA (SetupPath=SiteTemplates\PWA) - "Project Web Access Site"
    6215 - PWS (SetupPath=SiteTemplates\PWS) - "Project Workspace"
    14483 - OFFILE - "Records Repository", "Records Repository"

    Hope you like this post and will write more these kind of posts. We know plenty of things but some of the things are very hard to find. I will post all those kind in my blog. Keep checking the blog.

    Sunday, 15 August 2010

    Check string contains numbers in T-SQL

    I know this is looking very simple when we read. But, I had a requirement where I need to filter strings from string data type column in T-SQL. Means, some strings in database having numbers in them, and I need to get them out and do some processing. When I started implementing this, I had so many ideas and thought like, looping through all characters in each string and check whether it has numbers in it or not. But, this is not efficient and may be a stupid implementation. And after thought about it sometime, started reading T-SQL documentation and found a wonderful function which is already built in in T-sql. I am saved. Very happy to see that function and that is working very great.

    The function name called "PATINDEX". Which requires two parameters. 1. Regular expression and another is 2. input string. It returns the value of the index where it finds the given expression. If it is greater than 0 then it found the match, otherwise no.

    Usage:
    DECLARE @inputStr Varchar(100);
    SET @inputStr = 'This costs 35$';

    IF PATINDEX('%[0-9]%',@inputStr) > 0
    BEGIN
    --Write some logic here
    PRINT 'YES, The string has numbers';
    END
    ELSE
    BEGIN
    --Write some logic here.
    PRINT 'NO, The string does not have numbers';
    END

    It's very simple. Right? Now, I can use this in the single SELECT query and using CASE, WHEN I can display all strings which has the numbers in it from a table.

    And now, vice versa.. How to find whether a string contains alphabets. [There are possibilities that in database may have bad data. The numbers are also stored in the string type. A very bad design, but when we got to working on these type of projects, we have to find a way to refine it and make it more reliable and efficient.] So, in the same code, just change the first parameter of PATINDEX from '%[0-9]%' to '%[a-z]%'. That's it. The expression change is what we need to do there. You can try with any expression as per your requirements and solve the problems.

    Hope you like this post and still we need to know plenty of options already exists in technologies. Explore more and know more and save time.

    Monday, 9 August 2010

    Visual Studio intellisense for HTML 5

    It's the time to use the new technologies like HTML 5. Everyone of us knew about what this is and how easy now to generate some nice and rich UI without put much efforts. No complex javascript, no silverlight or flash is required most of the time and many more advantages. There are plenty of changes in CSS too. So, I believe we should start using HTML 5 in our applications. Because almost all browsers are supporting it.
    After I have written some posts on Visual Studio intellisense on Jquery and SharePoint 2010 ECMAscript Client OM, I want to write similar on the intellisense for HTML 5.

    This is very simple process than any other we have followed.

    1. Download the HTML5 intellisense file from the official vs tools site. Visual Studio intellisense for HTML 5. Applies to both VS 2010 and VS 2008.
    Note: In internet there are few sites already written related to this post. But, they are not providing the valid HTML 5 XSD files. They are downloading files from somewhere else and giving us. Those files are not up to date. So, try to download the files always from the site who created them. In this case Microsoft. The link I have given is official VS tools web site.
    2. Now run the file and select the preferences and finish the installer.
    3. Now you can see new files updated with the name HTML_5.XSD at the location: C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Packages\schemas\html [For VS 2008] and C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\schemas\html [For VS 2010].
    4. And the MSI update we have ran automatically updates the registry key and other settings. So, no more changes we have to do manually.
    5. Now, if you have opened the Visual Studio, please close it and reopen it.
    6. Now, from the Visual Studio toolbars, "HTML Source Editing" we have a drop down for selecting the HTML version as shown below.
     7. Once we have selected that option we are good to go and write HTML 5 code as shown below.
    8. In the above code sample, I am trying to  render a video and it is showing me all the attributes for the video tag.

    That is it!!! There we are.
    Hope you liked it.