Clever little tip from Aggarwal Saurabh - you can filter the contents of a SharePoint list view by appending a couple of querystring values to the address.
For example, if you have a list view including a field named "ProductID", you can filter a preset list view to only show items for a Products with ID "123" by adding the following querystring to the page URL:
?FilterField1=ProductID&FilterValue1=123
Could be handy!
Wednesday, November 28, 2007
Tuesday, November 6, 2007
Why does my modal dialog box open another browser on submit?
Currently I am creating an application where a modal dialog box opens when the NewForm.aspx page for a WSS list is opened, to search against an external data source and pass the results back to the form (I'll let you know if this proves to be a viable design pattern!).
The default behaviour of the modal dialog has been driving me a little crazy - when the form in the ASP.Net page in the modal dialog box is submitted by clicking on a button in that page, that same form was opening in a new browser window. The dialog was also remaining open.
Finally came across the solution tucked away in a forum answer by Ken Dopierala Jr. His tip:
Remember, when you post back to a Modal page you must put: <base target="_self"> in the <head> section of the HTML on that page.
And that is all it needed to take the nastiness away, just adding that simple tag into the PlaceHolderAdditionalPageHead placeholder of the WSS page being presented in the dialog. Thanks, Ken!
The default behaviour of the modal dialog has been driving me a little crazy - when the form in the ASP.Net page in the modal dialog box is submitted by clicking on a button in that page, that same form was opening in a new browser window. The dialog was also remaining open.
Finally came across the solution tucked away in a forum answer by Ken Dopierala Jr. His tip:
Remember, when you post back to a Modal page you must put: <base target="_self"> in the <head> section of the HTML on that page.
And that is all it needed to take the nastiness away, just adding that simple tag into the PlaceHolderAdditionalPageHead placeholder of the WSS page being presented in the dialog. Thanks, Ken!
Saturday, October 27, 2007
Creating a new form in a list by copying an existing form (in code)
To copy an existing form in a WSS list, and to add a new content editor web part to that list, use the SPFile class (not the SPForm collection of the list):
//Copy the NewForm.aspx to NewForm_new.aspx
string formPath = "Lists/ClientTest/NewForm.aspx";
string newformPath = formPath.Replace(".aspx", "_new.aspx");
SPFile form = web.GetFile(formPath);
form.CopyTo(newformPath, false);
//Get a reference to the new form, and create a new content editor web part containing onload JavaScript
SPFile copiedForm = web.GetFile(newformPath);
SPLimitedWebPartManager wpManager = copiedForm.GetLimitedWebPartManager(PersonalizationScope.Shared);
//Create the new web part
ContentEditorWebPart wpContent = new ContentEditorWebPart();
XmlDocument xmlContent = new XmlDocument();
XmlElement el = xmlContent.CreateElement("El");
el.InnerText = "";
wpContent.Content = el;
wpManager.AddWebPart(wpContent, "Main", 0);
The JavaScript adds an onload handler to the page, allowing for behaviours to modify the content of the standard list form for example.
//Copy the NewForm.aspx to NewForm_new.aspx
string formPath = "Lists/ClientTest/NewForm.aspx";
string newformPath = formPath.Replace(".aspx", "_new.aspx");
SPFile form = web.GetFile(formPath);
form.CopyTo(newformPath, false);
//Get a reference to the new form, and create a new content editor web part containing onload JavaScript
SPFile copiedForm = web.GetFile(newformPath);
SPLimitedWebPartManager wpManager = copiedForm.GetLimitedWebPartManager(PersonalizationScope.Shared);
//Create the new web part
ContentEditorWebPart wpContent = new ContentEditorWebPart();
XmlDocument xmlContent = new XmlDocument();
XmlElement el = xmlContent.CreateElement("El");
el.InnerText = "";
wpContent.Content = el;
wpManager.AddWebPart(wpContent, "Main", 0);
The JavaScript adds an onload handler to the page, allowing for behaviours to modify the content of the standard list form for example.
Thursday, October 18, 2007
Error in Custom Document Library View
When creating custom document library definitions using the view files output by the SharePoint Solution Generator, you may see the following error on the custom view pages in an instance of the libary:
An error occurred during the processing of ....... Only Content controls are allowed in a content page that contains Content controls.
This is caused by invalid text in the ASPX file - the solution generator adds a comment XML node to the top of each view file, and this needs to be deleted before deploying that view.
An error occurred during the processing of ....... Only Content controls are allowed in a content page that contains Content controls.
This is caused by invalid text in the ASPX file - the solution generator adds a comment XML node to the top of each view file, and this needs to be deleted before deploying that view.
Checkin Page Shows Error For Document Library
Have been very busy creating lots of solutions to define a raft of lists and document libraries. One technique I have experimented with is as follows:
I came across an issue with a document library created using one of the custom list definitions. Everything seemd to work in the document library except for checking in a document - the checkin.aspx page simply displayed an error stating
"Value does not fall within the expected range"
Don't ya love that one!! Lots of investigation uncovered the cause - a malformed content type. The document library used one custom content type, and one of the field elements in the field section of the document library schema.xml file had a mispelt name attribute. Amazing that I could still add a document, and could edit the metadata values!
- Manually define the site containing the lists
- Use the SharePoint Solution Generator to create schemas for the lists
- Run my own tool across these schemas to generate site column and content type definitions. The tool also removes some of the invlaid attributes in the schema field definitions that are created by the solution generator (I'll publish the tool here sometime soon)
- Create solutions and features in Visual Studio using these XML definitions.
I came across an issue with a document library created using one of the custom list definitions. Everything seemd to work in the document library except for checking in a document - the checkin.aspx page simply displayed an error stating
"Value does not fall within the expected range"
Don't ya love that one!! Lots of investigation uncovered the cause - a malformed content type. The document library used one custom content type, and one of the field elements in the field section of the document library schema.xml file had a mispelt name attribute. Amazing that I could still add a document, and could edit the metadata values!
Thursday, August 30, 2007
Visio Stencil of SharePoint Design Shapes
When creating site and application designs for SharePoint, I have wanted to illustrate the elements that comprise the solution's architecture.
Diagrams at this level are very valuable for explaining the proposed design to a client, and also for summarising the elements involved ("a picture is worth....").
So I have created a Visio stencil containing a few useful shapes.
See an example of the shapes, and download the stencil, from here
Diagrams at this level are very valuable for explaining the proposed design to a client, and also for summarising the elements involved ("a picture is worth....").
So I have created a Visio stencil containing a few useful shapes.
See an example of the shapes, and download the stencil, from here
Wednesday, August 22, 2007
Debugging SharePoint Custom Code
Great article about debugging SharePoint applications. It also suggests designing code to facilitate debugging, which seems a very sensible idea to me (particularly when combined with the idea of designing to "fail fast", thereby ensuring that exceptions are not hidden by the code)
One MOSS site I developed recently includes several event handlers and timer jobs. Each of these includes a common class to write error messages to a custom list in the site when exceptions occur. Having a central location within the site to monitor error message has proven effective - one advantage is that I can set up alerts in case of exceptions.
Using the facilities native to SharePoint (liist, alerts, etc) simplifies development and gives huge flexibility in using the resulting data.
One MOSS site I developed recently includes several event handlers and timer jobs. Each of these includes a common class to write error messages to a custom list in the site when exceptions occur. Having a central location within the site to monitor error message has proven effective - one advantage is that I can set up alerts in case of exceptions.
Using the facilities native to SharePoint (liist, alerts, etc) simplifies development and gives huge flexibility in using the resulting data.
Subscribe to:
Posts (Atom)