A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Saturday, June 27, 2009

One of more field types are not installed properly

Here is another small tip. If you get the following error, change the field name that you are using in your SPQuery to the "internal" field name and that should resovle your issue.
One of more field types are not installed properly
Well, I won't go into details as this is not a new topic and has been discussed several times on different blogs and forums but why I wanted to post this tip again was the reason that I have seen on different blogs where authors have mentioned that internal names should be used if there are spaces in the field name. That means if there are no spaces in the field name and you use the field name in the SPQuery, you shouldnt get this error. Right? That might work on your development machine but as soon as you move the solution to the staging or production environment, you start seeing this error and then you start scratching your head that there is nothing wrong with the query and you have already tested it in DEV environment then what is the cause of the error on other servers. You start fiddling with your database and other code that has no relationship whatsoever with the query code. So, the suggestion is to use the internal name in first place. That will work everywhere, on your DEV and also on staging and prod. You can use field.InternalName to get the internal name of the field where field is an SPField object. You can also use free tools like U2U CAML Builder to get the internal names of the fields. One last thing, I have often seen blogs where authors mention that simply replacing the space with  _x0020_ will resolve the issue. the authors have also given the code that shows how you can replace space character with _x0020_ but again that might work in your DEV environment but not necessarily on prod servers. For example, following is the name of one field in my list:
fc5bb16d_x002d_5336_x002d_45a6_x002d_b6e5_x002d_0c9e8de73e26
The real field name is "CurrentActivityStatus". Note there are no spaces in this field name so I shall assume it will be safe to use this name in the code but no, you will get the error if you did not use the internal name.
Comments/feedback welcome!
Update:
Someone asked me how to get the internal name using code. Here iit is:
list.Fields[FIELD DISPLAY NAME].InternalName.ToString()
Here list is an instance of SPList object.

Thursday, June 25, 2009

Reports: Michael Jackson dies at the age of 50

Reports say Michael Jackson has died after suffering a cardiac arrest. He was 50. It is indeed a very sad news. He was the king. I was a big fan of him.

Create a visual studio template for InfoPath

If your jobs is to design InfoPath forms on a regular basis, it will be a good idea for you to create a visual studio template. Add basic code like validation functions, etc and basic layout with common fields and save it as a template. You can use this template to create new InfoPath projects. New projects will have all the basic fields, layout and common functions and it will save you lot of time. To create the template, create a new visual studio project for InfoPath. Design layout and add code. That's the easy part that you might have already known. Now, to create the template, go to "File" menu and select "Export Template".  If you don't see that option, you may have to reset the visual studio settings.
To do that, click cancel to close the "Export Wizard" and go to "Tools" menu and select "Import and Export Settings...".
You will be shown "Import and Export Settings Wizard". Select "Reset all settings" and click "Next".
Select option "No, just reset settings, overwriting my current settings" and click "Next".
From the list shown, select your appropriate environment. For example, if you are creating a template that has C# code and will be used for C# projects, select "Visual C# Development Settings". Likewise, for VB, you can select the VB development settings. Click "Finish"
Now go to "File" menu again and select "Export Template" option. If it still doesn't work, close and re-open visual studio.
Select "Project Template" and click "Next". If your solution has more than 1 project. The drop down at the bottom will show all the projects that are part of the solution and you will have to select one.
On the next screen, you can select icon, template name, template description, etc. Choose the output location and click "Finish".
The wizard will create a zip file that will contain all the necessary files required to create a new project.
Copy this zip file to the following folder on your development machine:
C:Documents and Settings[Current User]My DocumentsVisual Studio 2005TemplatesProjectTemplatesVisual C#
If it's a VB template, copy it to the "Visual Basic" folder.
Now, open visual studio, and in new project wizard, select project type "Visual C#" (OR Visual Basic if you created a VB template). The new template will appear under "My Templates". Select the template, change it's name and location and click "OK" to create the project.





Error: InfoPath cannot save the following form: Template1

I got this error when I was converting an InfoPath form (XSN) to a Visual Studio project. To create a visual studio project out of an XSN template, create an InfoPath project in Visual Studio. Rename the .XSN to .CAB and unzip the .cab file using any zip/unzip utility. Copy all the unzipped files to "InfoPath Form Template" folder in your new Visual Studio project. That's it. You get the error when you make changes to manifest.xsf and try to save them. To get rid of the error, make sure the files you copied to the project are not read-only. Remove the read-ony atribute if they are read-only. Second, open the manifest.xsf in notepad and remove the old paths from the file. Locate attribute "publishurl" in the file and clear it's value. It points to an old publish location which might not be available in your current environment.  Then, locate "runtimeCompatibilityURL" attribute and change it's value to your current server URL The URL should point to the formservices.asmx. The URL will be something like http://sharepointserver/_vti_bin/FormsServices.asmx. Save the file. Close and re-open your visual studio project. Now you can save the changes.

Monday, June 1, 2009

Tip: Don't use "&" in instance.xml when creating a WSP

Here is a small tip for you. If you get a parsing error when deploying a WSP for one of your SharePoint lists and the list has data that uses "&", replace it with "&". to get rid of the error. For example:
<Field Name="IceCream">Ben & Jerry</Field>
List with this data will not deploy. Use the following:
<Field Name="IceCream">Ben &amp; Jerry</Field>