RSS

Category Archives: Webpart

Programatically select and bind Sharepoint list items to ASP.NET controls


  • Open Visual Studio 2010
  • Create New Project
  • Select your Sharepoint site
  • Create Visual Webpart
  • Add LAbels,Textboxes or Dropdownlist (NOTE: Update control names in your code accordingly)
  • Use below code in page load event

try
{

SPQuery query = new SPQuery();
query.Query = “”;
query.ViewFields = “”;
query.RowLimit = 100;

using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{

using (SPWeb web = site.OpenWeb())
{

SPList list = web.Lists.TryGetList(“—ADD LIST NAME—“);

//Check List Exists

if (list != null)

{

//Check ITEMS Exists

if (list.GetItems(query).GetDataTable() != null)
{
DataTableReader rdr = list.GetItems(query).GetDataTable().CreateDataReader();

if (rdr.Read())

//Bind list items to ASP.NET Label

Label1.Text = rdr[“Test_x0020_Item1”].ToString();
Label2.Text = rdr[“TestField2”].ToString();

//To bind DROPDOWNLIST uncomment below code
// dropdownlist1.DataSource = rdr;
// dropdownlist1.DataTextField = “Title”;
// dropdownlist1.DataValueField = “Title”;
// dropdownlist1.DataBind();

//To bind REPEATER uncomment below code
// Repeater1.DataSource = rdr;
// Repeater1.DataBind();

rdr.Close();

}
else
{
lblInfo.Text = “No Items Found”;
}
}
else
{
lblErrorMessage.Text = “List not found.Please make sure list is created and go to webpart settings to add the List name “;
}
}

}
}

catch (Exception ex)
{
lblErrorMessage.Text = ex.Message.ToString();
}

Advertisements
 
 

Tags: ,

Programatically Insert Items to Sharepoint 2010 List using C#.net


  • Open Visual Studio 2010
  • Create New Project
  • Select Your Sharepoint site
  • Create New Visual Webpart
  • Add Textbox,Label and Button as required(NOTE: Controls names You need to update in below code)
  • Add below code in button click event the code

try
{

using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb web = site.OpenWeb())
{

SPList List = web.Lists.TryGetList(“—ADD LIST NAME—“);
if (List != null)
{

SPListItem NewItem = List.Items.Add();

{
web.AllowUnsafeUpdates = true;

NewItem[“Title”] = Label1.Text;
NewItem[“Employee Name”] = Label2.Text;
NewItem[“Comments”] = Textbox1.Text;

NewItem.Update();

//int newID = NewItem.ID;

web.AllowUnsafeUpdates = false;

lblInfo.Text = “Item Inserted Successfully.”;

}
}
}

}

}
else
{
lblErrorMessage.Text = “List not found. Configure the list from webpart settings”;
}
}

}
}

catch (Exception ex)
{
lblErrorMessage.Text = ex.Message.ToString();
}

 
2 Comments

Posted by on November 14, 2012 in Code Snippets, Uncategorized, Visual web part

 

Tags: , ,

Error occurred in deployment step ‘Recycle IIS Application Pool’: Provider load failure


The Bug

When you try to deploy or retract a SharePoint 2010 solution from visual studio 10 you get below error message:
Error occurred in deployment step ‘Recycle IIS Application Pool’: Provider load failure

Solution

Restart the SharePoint 2010 User Code Host service resolved the issue. Try below powershell command.

restart-service SPUserCodeV4

 
Leave a comment

Posted by on August 14, 2012 in Bug, Error, Sharepoint Server 2010, Webpart

 

Tags: ,

Visual web part deployment error : – Recycle IIS application pool”: The local sharepoint server is not available


When you try to deploy Visual webpart using Visual studio 2010 you will get following error on deployment :Error occured in deployment step: “Recycle IIS application pool”: The local sharepoint server is not available. Check that the server is running and connected to the sharepoint farm.

Cause:-
The account you are running Visual Studio does not have sufficient permission in SQL server database

Solution:-
Make the account you are running Visual Studio a member of the db_owner role on the sharepoint_config and sharepoint_admin databases.

 

 
2 Comments

Posted by on October 19, 2011 in Error, Visual web part

 

Tags: ,

SLAM! SharePoint List Association Manager to define relationships (one to one, one to many, many to many)


Today i have seen an amazing stuff in codeplex which is very useful for developers who is struggling to define relationships (one to one, one to many, many to many) between SharePoint lists (or Content Types).

Here is a demo video  about SLAM..

Download the SLAM  from here

 
 

Tags: ,

Limit length of dataview webpart title text character


Limit Announcment list title length

To alter the character limit of an Announcements List, there is an attribute that must be set through SharePoint Designer on the page that contains the web part. Perform a search for the string “Limit Len=” on the page in question and alter the value to reflect the character limit you would like.The default character limit attribute is set to 250 characters.

Limit Dataview webpart of any list title text

<xsl:value-of select=”concat(substring(@Title,1,100),’…[+]’)” disable-output-escaping=”yes” />

eg: 

<td>
    <a href=”http://mylink/Pages/Test.aspx?id={@ID}”><xsl:value-of select=”concat(substring(@Title,1,100),’…[+]’)” disable-output-escaping=”yes” /></a><xsl:if test=”ddwrt:IfNew(string(@Modified))”><IMG SRC=”/_layouts/1033/images/new.gif” alt=”New” /></xsl:if>

   </td>

 
2 Comments

Posted by on April 1, 2009 in Sharepoint Designer, Webpart

 

Tags: ,

Understanding Field Controls and Web Parts in SharePoint Server 2007 Publishing Sites


A smart topic to learn the details of Microsoft Office SharePoint Server 2007 field controls and Web Parts and how they differ, and best practices for when to use each type of control.

Author: Andrew Connell, Andrew Connell Inc. (Microsoft MVP)

MSDN link: http://msdn.microsoft.com/en-us/library/dd571480.aspx

Contents

Download the code samples that accompany this article: Windows SharePoint Services 3.0 Content Editor Web Part Link Fixup and Prohibit Content Editor Web Part.

 
Leave a comment

Posted by on March 22, 2009 in Development, Webpart