Wednesday, November 18, 2009

SharePoint : Setting List column values

Here is the code snippet where I am setting a List column called "Has Payment" depending on few conditions:

string strSiteCollPath = "your Site Collection path";
using (SPSite siteCollection = new SPSite(strSiteCollPath))
{
using (SPWeb siteWeb = siteCollection.OpenWeb())
{
SPList lstPayment = siteWeb.Lists["XYZ"];
SPList lstInvoiceSummary = siteWeb.Lists["ABC"];

foreach (SPItem item in lstInvoiceSummary.Items)
{
string strDocNumber = item["documentNumber"].ToString();
SPQuery query = new SPQuery();
query.Query = "your SPQuery";
SPListItemCollection coll = lstPayment.GetItems(query);
int count = coll.Count;

if (count > 0)
{
item["Has Payment"] = "Yes";
item.Update();
}
else
{
item["Has Payment"] = "No";
item.Update();
}
}
}
}

Basic SilverLight WebPart

Here goes the link to a Basic Hello World Silver Light webpart
http://philwicklund.com/archive/2008/05/26/how-to-build-a-%E2%80%9Chello-world%E2%80%9D-silverlight-web-part-for-a-sharepoint-site-in-10-easy-steps-part-2-of-2-deploying-a-silverlight-application-into-sharepoint.aspx

Monday, November 9, 2009

C# :Writing DataTable to a text file

Here goes the code to write a data table to a text file:

//Writing to a text file
int count = 0;
StreamWriter sw = null;
try
{
sw = new StreamWriter(@"C:\Users\asoory\Desktop\UniqueConsultantNames.txt", false);
for (count = 0; count < dtList.Columns.Count - 1; count++)
{
sw.Write(dtList.Columns[count].ColumnName + "");
}
sw.Write(dtList.Columns[count].ColumnName);
sw.WriteLine();
foreach (DataRow row in dtList.Rows)
{
object[] array = row.ItemArray;
for (count = 0; count < array.Length - 1; count++)
{
sw.Write(array[count].ToString() + "");
}
sw.Write(array[count].ToString());
sw.WriteLine();
}
sw.Close();
}
catch (Exception ex)
{
}

Thursday, November 5, 2009

SPQuery Error :One or more field types are not installed properly. Go to the list settings page to delete these fields

I kept receiving this error for a list when I was using a SPQuery to fetch items from it.
"One or more field types are not installed properly. Go to the list settings page to delete these fields"
The error came up because one of the fields I was calling was not a column of the list.
I removed it from the CAML query and it worked.
So ,I guess this error crops up when the CAML is not properly formed.
U2U CAML query builder is very useful in debugging such errors.