14 May 2011

How to get a display form in sharepoint public site

This time I will present to you the difference between the two ways that would have the display form (or new/edit) in sharepoint public site .

As I explained before, I had to activate the "Lockdown Feature" to lock the form from public Web site. Also, I said that if we want to see our form, we must create a new custom form using SharePoint designer. The SPD will help us to carry out the redirect (with "Supporting Files").

I was asked Yesterday to create a WebPart that displays links that lead to the Item list (our custom form).
I know the code that refers to display form
list.Forms[PAGETYPE.PAGE_DISPLAYFORM].ServerRelativeUrl;
The problem is that this code refers to the original form (from list folder) and the "lockdown feature" lock me this path (401 unauthorized).
How I will get my form?
Solving this problem I created a Console Application that will help me



I found the following code:
list.ContentTypes[0].DisplayFormUrl
To get the real form I need to go list ContentType, and then to get the real form.
Of course to get the path you will need to concatenate list.ParentWebUrl
Here is the code of my Console Application:

using Microsoft.SharePoint;
namespace ConsoleApplication1
{
   class Program 
   {
        static void Main(string[] args)
        {
           using (SPSite site = new SPSite("http://mysite/"))
           {
               using (SPWeb web = site.OpenWeb())
               {

                   SPList list = web.Lists["mylist"];

                   string url1 = list.Forms[PAGETYPE.PAGE_DISPLAYFORM].ServerRelativeUrl;

                   string url2 = list.ContentTypes[0].DisplayFormUrl;

               }

           }

        }

    }
}

No comments:

Post a Comment