10/29/2011

URL of Web Part Maintenance Page in SharePoint 2010

URL of Web Part Maintenance Page in SharePoint 2010
Hey Folks,

While learning SharePoint 2010, I do lots of mistakes which crashes my SharePoint 2010 Home Page.

I do add weird web parts which causes the problem.

The easiest way to get rid of this is to just delete the web part form your page and to do it you need to go to the Web Part Maintenance Page of SharePoint 2010.

Do you know from where or how to go??

If yes, good you are a pro!!

If No, Welcome To My World :)

Suppose your Home Page Site URL is :

http://nick-pc/

When you enter into the address bar of your browse, you get below full URL :

http://nick-pc/SitePages/Home.aspx

What you need to do to go to the Web Part Maintenance Page of SharePoint 2010 is just append, ?contents=1

http://nick-pc/SitePages/Home.aspx?contents=1

And you are there :D

Thanks and Have Fun!!!!!

10/05/2011

How To : HyperLink Column in SPGridView for SharePoint 2010

How To : HyperLink Column in SPGridView for SharePoint 2010
Below is the code :

 

using System;

using System.ComponentModel;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;

using System.Data;

 

namespace VisualWebPartProject5.VisualWebPart1

{

[ToolboxItemAttribute(false)]

public class VisualWebPart1 : WebPart

{

protected override void CreateChildControls()

{

GridView gview = new GridView();

SPList list = SPContext.Current.Web.Lists["Projects"];

SPQuery query = new SPQuery();

 

query.Query = "<OrderBy><FieldRef Name=\"Project\" Ascending=\"True\"/></OrderBy>";

 

query.ViewFields = "<FieldRef Name=\"Project\" Nullable=\"TRUE\" /><FieldRef Name=\"Client\" Nullable=\"TRUE\" /><FieldRef Name=\"URL\"

 

Nullable=\"TRUE\" />";

 

query.ViewFieldsOnly = true;

 

SPListItemCollection lic = list.GetItems(query);

 

DataTable dt = lic.GetDataTable();

 

dt.Columns.Add("Temp", typeof(string));

 

foreach (DataRow r in dt.Rows)

{

r["Temp"] = r["URL"];

}

 

gview.DataSource = dt;

 

HyperLinkField linkField = new HyperLinkField();

linkField.HeaderText = "Text";

linkField.DataTextField = "Project";

linkField.DataNavigateUrlFields =new string[] { "Temp"};

linkField.Target = "_blank";

gview.Columns.Add(linkField);

gview.DataBind();

this.Controls.Add(gview);

 

}

}

}

 

10/03/2011

Hyperlink Column Type in SharePoint 2010 : How to open in new window?

Hyperlink Column Type in SharePoint 2010 : How to open in new window?
Hey Folks!!

Recently I have created a custom list.  Into my custom list, I had one column which was of type Hyperlink.

I added my new custom list as a web part.  Works just fine!!  I had 4-5 URLs in my custom list or web part.

When I clicked on one of the URL....Woha!!!!

Instead of opening the URL in new window, it just opened in same page??!!

I went back to edit my column type, but I couldn't found the way or option to ask it to open any URLs into new window.

I googled it but again I found very complex and an un-easy way to achieve the same.

I wanted something pretty straight forward and easy to use and I think you too will expect the same right?

So, Let's Go :)

Steps :

1. Go to list

2. Site Actions -> Edit in SharePoint Designer

3. In Navigation....Select All Files -> Lists -> Click on your list name -> AllItems.aspx

4. Click on any of the URLs

5. Tag Properties change "target" Value from _self to _blank (If you can't see this, follow the below steps)

6. Click on the link and the click on ">" to display Common xsl:value-of Tasks

7. Click on Hyperlink options...

8. Click "Yes" if its a trusted environment. message

9. Click "Target Frame..." button

10. Select "New Window"

11. Click OK Twice.

12. If this is not setting the target value to _blank then edit the tag in code

Click Save, Refresh your SharePoint 2010 Page and click on any of the URLs :) It's done!!

<a href="{$url}"><xsl:value-of select="$desc" /></a>

How To : Programmatically Create A Custom List in SharePoint 2010 using Visual Studio 2010

How To : Programmatically Create A Custom List in SharePoint 2010 using
Visual Studio 2010
Let's  create a Candidates List in SharePoint 2010 using Visual Studio 2010:

A list will be having following columns:

1. Title

2. Name

3. Home City

And then we'll add rows into it programmatically.

Steps :

1. Open Visual Studio 2010 -> File -> New Project -> Visual C# (You may choose Visual Basic) -> SharePoint -> 2010

1.1     Deploy it on Farm Level

2.  Select List Definition as Project Type, give a proper name to your List Definition and press OK.

3.  In Solution Explorer, you will see few files listed automatically by Visual Studio 2010 itself.

4.  We need to look into below files :

1. ListDefinition1 -> ListInstance1 -> Elements.xml

2. ListDefinition1 -> Elements.xml

3. ListDefinition1 -> Schema.xml

5.  First, let's start with ListDefinition1 -> ListInstance1 -> Elements.xml

Change the ListIntance as below :
<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <ListInstance Title="SampleList1"

                OnQuickLaunch="TRUE"

                TemplateType="10001"

                Url="Lists/SampleList1-ListInstance1"

                Description="My List Instance">

    <Data>

      <Rows>

        <Row>

          <Field Name ="Title">Mr</Field>

          <Field Name ="Name">Naimish</Field>

          <Field Name="HomeCity">Las Vegas</Field>

        </Row>

        <Row>

          <Field Name ="Title">Mr</Field>

          <Field Name="Name">Vishal</Field>

          <Field Name="HomeCity">New York</Field>

        </Row>

        <Row>

          <Field Name ="Title">Mr</Field>

          <Field Name="Name">Vijay</Field>

          <Field Name="HomeCity">Chicago</Field>

        </Row>

      </Rows>

    </Data>

  </ListInstance>

</Elements>

6.  Change ListDefinition1 -> Elements.xml

 

Please note that Field IDs will be different for your project. To generate your Field IDs (GUID), In Visual Studio 2010, Go To Tools -> Create GUID



<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<Field ID="{E9C12CCA-26E4-47CA-A388-8959C11CDD13}" Name="Title" Type="Note" DisplayName="Title" Required="FALSE" ></Field>

<Field ID="{64B80007-B8AD-4312-B4CA-ADF57500EBF8}" Name="Name" Type="Note" DisplayName="Name" Required="FALSE" ></Field>

<Field ID="{AAABDB73-F548-4D79-AED7-4BE42B9A05C3}" Name="HomeCity" Type="Note" DisplayName="HomeCity" Required="FALSE" ></Field>

<ContentType

ID="0x01004d360004c8074de6a25f4d8cdd3be8dd"

Name="SimpleList1"

Group="Custom Content Type"

Description="SimpleList1"

Version="0">

<FieldRefs>

<FieldRef ID="{E9C12CCA-26E4-47CA-A388-8959C11CDD13}"/>

<FieldRef ID="{64B80007-B8AD-4312-B4CA-ADF57500EBF8}"/>

<FieldRef ID="{AAABDB73-F548-4D79-AED7-4BE42B9A05C3}"/>

</FieldRefs>

</ContentType>

<!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List Definition project item, an error will occur when the project is run. -->

<ListTemplate

Name="ListDefinition1"

Type="10001"

BaseType="0"

AllowDeletion="FALSE"

DisallowContentTypes="FALSE"

OnQuickLaunch="FALSE"

SecurityBits="11"

Sequence="410"

DisplayName="SampleList1"

Description="My List Definition"

Image="/_layouts/images/itgen.png"/>

</Elements>

7. ListDefinition1 -> Schema.xml

<?xml version="1.0" encoding="utf-8"?>

<List xmlns:ows="Microsoft SharePoint" EnableContentTypes="TRUE" Title="SampleList1" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/SampleList1-ListDefinition1" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">

<MetaData>

<ContentTypes>

<ContentTypeRef ID ="0x01004d360004c8074de6a25f4d8cdd3be8dd"></ContentTypeRef>

<ContentTypeRef ID="0x01">

<Folder TargetName="Item" />

</ContentTypeRef>

<ContentTypeRef ID="0x0120" />

</ContentTypes>

<Fields>

<Field ID="{E9C12CCA-26E4-47CA-A388-8959C11CDD13}" Name="Title" Type="Note" DisplayName="Title" Required="FALSE" ></Field>

<Field ID="{64B80007-B8AD-4312-B4CA-ADF57500EBF8}" Name="Name" Type="Note" DisplayName="Name" Required="FALSE" ></Field>

<Field ID="{AAABDB73-F548-4D79-AED7-4BE42B9A05C3}" Name="HomeCity" Type="Note" DisplayName="HomeCity" Required="FALSE" ></Field>

</Fields>

<Views>

<View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">

<Toolbar Type="Standard" />

<XslLink Default="TRUE">main.xsl</XslLink>

<RowLimit Paged="TRUE">30</RowLimit>

<ViewFields>

<FieldRef Name="LinkTitleNoMenu"></FieldRef>

</ViewFields>

<Query>

<OrderBy>

<FieldRef Name="Modified" Ascending="FALSE"></FieldRef>

</OrderBy>

</Query>

<ParameterBindings>

<ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />

<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />

<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />

</ParameterBindings>

</View>

<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">

<Toolbar Type="Standard" />

<XslLink Default="TRUE">main.xsl</XslLink>

<RowLimit Paged="TRUE">30</RowLimit>

<ViewFields>

<FieldRef Name="Attachments"></FieldRef>

<FieldRef Name="LinkTitle"></FieldRef>

</ViewFields>

<Query>

<OrderBy>

<FieldRef Name="ID"></FieldRef>

</OrderBy>

</Query>

<ParameterBindings>

<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />

<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />

</ParameterBindings>

</View>

</Views>

<Forms>

<Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />

<Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />

<Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />

</Forms>

</MetaData>

</List>

And Done :) Refresh your SharePoint 2010 site!!

That's it!!

Though I have tried my best to explain it in as simple way was possible, I would highly recommend to go and read Ben Hedges article on Creating SharePoint 2010 List Definitions in Visual Studio 2010.

10/01/2011

Microsoft Visual Studio 2010 Bug : SharePoint List Definition Project Invalid Schema.xml

Microsoft Visual Studio 2010 Bug : SharePoint List Definition Project
Invalid Schema.xml
Surprised!!!!!

I wanted to simple create a custom list in SharePoint 2010, using Visual Studio 2010.

Stpes :

1. Open Visual Studio 2010

2. Got To File -> New -> Project

3. Select Visual C# (I selected C#, you may select VB.NET) -> SharePoint -> 2010

4. Select Project Type as List Definition

5. Give some name to your project and select OK.

6. Enter your SharePoint site URL to validate and deploy the solution as farm solution, click Next

7. Give some name to your List Definition

8. Select Custom List as type of the List Definition

9. Click on Finish

10. Visual Studio 2010 will list down few of the files (see in solution explorer).

11. Build The Project.

12. You will get below warnings:

Warning 1 The element 'View' in namespace 'http://schemas.microsoft.com/sharepoint/' has invalid child element 'ParameterBindings' in namespace 'http://schemas.microsoft.com/sharepoint/'. List of possible elements expected: 'ViewFooter, GroupByHeader, ViewEmpty, Xsl, PagedRecurrenceRowset, RowLimitExceeded, ViewData, ViewBody, PagedClientCallbackRowset, ViewStyle, ViewHeader, PagedRowset, Method, GroupByFooter' in namespace 'http://schemas.microsoft.com/sharepoint/'. c:\users\xxx\documents\visual studio 2010\Projects\ListDefinitionProject2\ListDefinitionProject2\ListDefinition1\Schema.xml 44 10 ListDefinitionProject2 

Warning 2 The 'Default' attribute is not declared. c:\users\xxx\documents\visual studio 2010\Projects\ListDefinitionProject2\ListDefinitionProject2\ListDefinition1\Schema.xml 54 18 ListDefinitionProject2

Warning 3 The element 'View' in namespace 'http://schemas.microsoft.com/sharepoint/' has invalid child element 'ParameterBindings' in namespace 'http://schemas.microsoft.com/sharepoint/'. List of possible elements expected: 'ViewFooter, ViewFields, GroupByHeader, Query, ViewEmpty, Xsl, PagedRecurrenceRowset, RowLimitExceeded, ViewData, ViewBody, PagedClientCallbackRowset, ViewStyle, ViewHeader, PagedRowset, Method, GroupByFooter' in namespace 'http://schemas.microsoft.com/sharepoint/'. c:\users\xxx\documents\visual studio 2010\Projects\ListDefinitionProject2\ListDefinitionProject2\ListDefinition1\Schema.xml 56 10 ListDefinitionProject2

 Warning 4 The element 'View' in namespace 'http://schemas.microsoft.com/sharepoint/' has invalid child element 'ParameterBindings' in namespace 'http://schemas.microsoft.com/sharepoint/'. List of possible elements expected: 'ViewFooter, ViewFields, GroupByHeader, ViewEmpty, Xsl, PagedRecurrenceRowset, RowLimitExceeded, ViewData, ViewBody, PagedClientCallbackRowset, RowLimit, ViewStyle, ViewHeader, PagedRowset, Method, GroupByFooter' in namespace 'http://schemas.microsoft.com/sharepoint/'. c:\users\xxx\documents\visual studio 2010\Projects\ListDefinitionProject2\ListDefinitionProject2\ListDefinition1\Schema.xml 92 10 ListDefinitionProject2

Below is full Schema.xml file :

<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" Title="ListDefinitionProject3 - ListDefinition1" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/ListDefinitionProject3-ListDefinition1" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
<MetaData>
<ContentTypes>
<ContentTypeRef ID="0x0104">
<Folder TargetName="Announcement" />
</ContentTypeRef>
<ContentTypeRef ID="0x0120" />
</ContentTypes>
<Fields>
<Field ID="{7662cd2c-f069-4dba-9e35-082cf976e170}" Type="Note" RichText="TRUE" RichTextMode="FullHtml" IsolateStyles="TRUE" NumLines="15" Name="Body" DisplayName="$Resources:core,camlid2;" Sortable="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Body"></Field>
<Field ID="{6a09e75b-8d17-4698-94a8-371eda1af1ac}" Type="DateTime" Name="Expires" DisplayName="$Resources:core,camlid3;" Format="DateOnly" FromBaseType="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Expires"></Field>
</Fields>
<Views>
<View BaseViewID="0" FreeForm="TRUE" Type="HTML" MobileView="TRUE" TabularView="FALSE">
<Toolbar Type="Standard" />
<XslLink>main.xsl</XslLink>
<Query>
<Where>
<Or>
<IsNull>
<FieldRef Name="Expires" />
</IsNull>
<Geq>
<FieldRef Name="Expires"></FieldRef>
<Value Type="DateTime">
<Today></Today>
</Value>
</Geq>
</Or>
</Where>
<OrderBy>
<FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
</OrderBy>
</Query>
<ViewFields>
<FieldRef Name="LinkTitleNoMenu" Explicit="TRUE"></FieldRef>
<FieldRef Name="Body" Explicit="TRUE"></FieldRef>
<FieldRef Name="Author" Explicit="TRUE"></FieldRef>
<FieldRef Name="Modified" Explicit="TRUE"></FieldRef>
<FieldRef Name="Attachments" Explicit="TRUE"></FieldRef>
</ViewFields>
<RowLimit>5</RowLimit>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,NoAnnouncements)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,NoAnnouncementsHowTo)" />
<ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,idHomePageNewAnnounce)" />
<ParameterBinding Name="MoreAnnouncements" Location="Resource(wss,MoreAnnouncements)" />
<ParameterBinding Name="ByText" Location="Resource(wss,2000)" />
</ParameterBindings>
</View>
<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,camlid4;" DefaultView="TRUE" MobileView="True" MobileDefaultView="True" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/announce.png" Url="AllItems.aspx">
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main.xsl</XslLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
</ParameterBindings>
<ViewFields>
<FieldRef Name="Attachments"></FieldRef>
<FieldRef Name="LinkTitle"></FieldRef>
<FieldRef Name="Modified"></FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
</OrderBy>
</Query>
</View>
<View BaseViewID="3" FreeForm="TRUE" Type="HTML" TabularView="FALSE">
<Toolbar Type="Standard" />
<XslLink>main.xsl</XslLink>
<Query>
<Where>
<Or>
<IsNull>
<FieldRef Name="Expires" />
</IsNull>
<Geq>
<FieldRef Name="Expires"></FieldRef>
<Value Type="DateTime">
<Today></Today>
</Value>
</Geq>
</Or>
</Where>
<OrderBy>
<FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
</OrderBy>
</Query>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
</ParameterBindings>
<ViewFields>
<FieldRef Name="LinkTitleNoMenu" Explicit="TRUE"></FieldRef>
<FieldRef Name="Body" Explicit="TRUE"></FieldRef>
<FieldRef Name="Author" Explicit="TRUE"></FieldRef>
<FieldRef Name="Modified" Explicit="TRUE"></FieldRef>
<FieldRef Name="Attachments" Explicit="TRUE"></FieldRef>
</ViewFields>
<RowLimit>3</RowLimit>
</View>
</Views>
<Forms>
<Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
<Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
<Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
</Forms>
<DefaultDescription>$Resources:onetid10;</DefaultDescription>
</MetaData>
</List>
 
I have submitted this bug at Microsoft -> https://connect.microsoft.com/VisualStudio/feedback/details/692514/microsoft-visual-studio-2010-bug-sharepoint-list-definition-project-invalid-schema-xml