A Practical Guide to SharePoint 2013

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

Monday, October 22, 2007

A deployment or retraction is already under way for the solution ... Publishing InfoPath form

You get this error when you try to publish an already published InfoPath form in SharePoint:
"A deployment or retraction is already under way for the solution ..."
If you go into the event log, you will notice different error messages related to this event. For example, one message will be as following:
EventType ulsexception12, P1 w3wp.exe, P2 6.0.3790.1830, P3 42435be1, P4 microsoft.office.infopath.server, P5 12.0.4518.0, P6 4541816a, P7 12961, P8 161, P9 nullreferenceexception, P10 8gec.
Another will look like the following:
An exception occurred during loading of business logic. (User: ServerAdministrator, Form Name: Teachers, IP: , Request: http://Server/_layouts/Formserver.aspx?XsnLocation=http://server/FormServerTemplates/teachers.xsn, Type: FileNotFoundException, Exception Message: Could not load file or assembly 'file:///C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12TemplateFeaturesFT-01-08f7ce0d-e5ba-7eab-8b14-ac2eb94f1addTeachers.dll' or one of its dependencies. The system cannot find the file specified.)
For more information, see Help and Support Center at
Now both these messages are misleading. The first one shows a "nullreferenceexception" and the other one mentions a missing file or dependency. Because of these messages I wasted time in trying to resolve the "nullreferenceexception" error but later it turned out that somehow the form didn't get published properly the first time we published it in SharePoint. Now when we were trying to republish the form but SharePoint was giving us errors. On each attempt SharePoint threw a new error message. One thing that I noticed was that the publishing process stopped the "Windows SharePoint Services Administration" service which was one of the reasons we were unable to republish the form. So check services and start this service if it's stopped and then run the following command:
stsadm -o execadmsvcjobs
If you try to publish the form without starting the "Windows SharePoint Services Administration" service, you will get the following error:
"The timer job for the operation has been created. However, it cannot be run because the administrative service for this server is not enabled."
So start the service and run the stsadm command. This will publish your form and hopefully, you will get rid of the error that said that there was a "nullreferenceexception" in your form. If you still get the same error (A deployment or retraction is already ...) then try running the following command to cancel the deployment that was started earlier:
stsadm -o canceldeployment -id <Timer Job ID>
Timer Job ID can be copied from "Central Administration > Operations > Timer Job Definitions" page. See the most recently created job, you can also verify by looking at the title. Right click the "Job" link and copy the URL. Locate the "JobId" parameter in the URL, this parameter contains the ID.

Tuesday, October 16, 2007

Null is null or not an object

Have you seen this error before? Did you find a solution? I was getting this javascript error on the click of a button that had a simple rule attached to it. Everytime I clicked the button, it produced this javascript error:
Null is null or not an object.
After some debugging, I noticed that the error was occuring in the "owsbrows.js". This file contained a line that was trying to load a value from the control that was clicked in the form. The control returned "null" and hence InfoPath generated this beautiful error message.
Reason?
The postback setting of the button was set to "Never".
Solution?
Set the postback setting of the button to "Always".
1. Right click the button.
2. Select "Button Properties".
3. Select "Browser forms" tab.
4. Select "Always". Note: Selecting the default recommended option "Only when necessary for correct rendering of the form (recommended)"will not solve this problem.
When you are using rules, you  must set the postback settings of the button to "Always" so that the click event sends data to the server everytime the button is clicked.
p.s. The error occurs in browser enabled forms.

InfoPath button with simple rule attached doesn't work!

I had a button in my form and there was a simple rule attached to this button. Rule was that If someone clicked the button, a (hidden) textbox would appear in the form, a very simple rule! Problem?? The button was not working. Somehow the event was not firing. I had this problem even before but simply changing the ID of the button resolved my problem but this time, changing the ID didn't work. I spent a couple of hours trying to find the cause but in the end, I needed a quick solution as I was short of time (as usual). The problem was resolved when I added an empty event handler for the button in the form.
 ((ButtonEvent)EventManager.ControlEvents["Button"]).Clicked += new ClickedEventHandler(Button_Clicked);
  public void Button_Clicked(object sender, ClickedEventArgs e)
        {
            // Write your code here.
        }
Now, I don't understand why some buttons work without an event handler and the others don't. I added two buttons to the form, one is firing the other is not! Why? I don't have time to find the cause at the moment, will spend some time on this on the weekend.

SPWeb fails to return the list

When working on large applications, we usually make mistakes and then spend time debugging the errors that occur because of the mistakes that we make during programming but there are some errors that occur even if you don't make any mistake. Have a look at the following code:
SPWeb web = Site.OpenWeb(SPContext.Current.Web.ID); string strList = SPContext.Current.Web.Url.Substring( .... substring processing ....);
SPList list = web.Lists[strList]; //This line gives error!
Do you see any problem with this code? I didn't notice any thing. It gave me the following error:
Value does not fall within the expected range.<BR/>Source: Microsoft.SharePoint<BR/>Stack trace: at Microsoft.SharePoint.SPListCollection.GetListByName(String strListName, Boolean bThrowException)
at Microsoft.SharePoint.SPListCollection.get_Item(String strListName)
The reason of the error turned out to be the list name. The list name had parentheses which resulted in the error. In small companies, you are the all in all when working on a project but in big companies or when working on large projects, there are several people involved in the project. The list was created by the SharePoint admin and I was getting the list name programmatically. I didn't know the list name had parentheses in it. When you load such a list in browser, SharePoint automatically removes parentheses from the list name and the list works fine but when you try to access the same list programmatically, SharePoint gives you an error. As you will notice, in the code above, I am extracting the list name from "SPContext.Current.Web.Url" and it returns the list name without parentheses in it while the actual list name has parentheses and hence you get an error. Even if you add parentheses to the list name (in your code), you still get an error but a different one. It's a SPException error and returns following message:
Action can not be completed.
Conclusion: Do not use parentheses in list name.

Wednesday, October 3, 2007

Invalid column name c2

SharePoint gives you this error when you try to search documents using the SPQuery object and you search by passing the document's Name. SPQuery object uses the internal field names so it's important to pass correct internal name for the correct field to be searched. By default, the "Name" field that is visible in the library has the internal name "LinkFilename" so when someone wants to search a document in the library using the "Name" field, obviously he uses the "LinkFilename" to search the document but strangely enough, it returns the following error:
"Invalid column name C2"
This error occurs in the sQL Server. SharePoint tries to search this field in the DB and returns an error when the field is not found. I haven't checked whether this field actually exists in the DB or not but we get an error. There are two more "Name" fields in the library. The internal names of the three "Name" fields are as following:
Name="LinkFilename" DisplayName="Name FieldType="Computed" -> default
Name="FileLeafRef" DisplayName="Name" FieldType="File"
Name="LinkFilenameNoMenu" DisplayName="Name" FieldType="Computed"
If you look at the definitions, you will notice that the FieldType of the two fields is "Computed" and for one field, it is "File". By default, it is the first field that is shown in the library. It has the FieldType "Computed". To search the document in the library using the "Name" field, you must use the second field that has the internal name "FileLeafRef". Although, this field is not visible in the library by default but it will return the document in the search. It's FieldType is "File" and therefore, you will have to pass the complete filename alongwith the extension in order for search to work and return the document. The third "Name" field also errors out. It is not necessary to make this field visible in the library to make the search work.
Sample query:
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='FileLeafRef'></FieldRef><Value Type='Text'>" + itemName + "</Value></Eq></Where>";
                           
SPListItemCollection listitems = list.GetItems(query);
"itemName" is the parameter that contains the file's name (passed from the interface or the calling function). It will be the complete name (alongwith extension), for example, document1.doc.