Tuesday, May 31, 2011

How to generate live data for chat webpart in sharepoint 2010

How to generate the live data for "Chart WebPart in SharePoint 2010" using SharePoint List.
Visit
http://www.codeproject.com/KB/TipsnTricks/LiveData_ChartWebPart.aspx

Tuesday, May 24, 2011

updating sharepoint list programmatically

updating sharepoint list programmatically
Recently I encountered the new requirement which wanted to create "Import SharePoint List"
There were more than 700 rows to be updated on a column value had null.
try
            {
                SPSite site = SPContext.Current.Site;
                SPWeb web = site.OpenWeb("http://mosstemp:5000");
                SPList list = web.Lists["Prospects"];

                SPQuery query = new SPQuery();
                query.Query = "";
                SPListItemCollection items = list.GetItems(query);

                foreach (SPListItem item in items)
                {

                    item["Status"] = "Not Called";
                    item.Update();

                }
               
                control = new LiteralControl();
                control.Text = "Updated";
            }
            catch (Exception ex)
            {
                control.Text = ex.InnerException.Message.ToString();
            }
You can't update the "look up" column in the sharepoint list.

Tuesday, May 17, 2011

Retrieve List Item using SharePoint Client Object

This code retrieve the sharepoint list item using SharePoint Client Object Model
ClientContext context = new ClientContext("http://WIN-ASNOSC246SV");
var web = context.Web;
context.Load(web);

List list = web.Lists.GetByTitle("Friends");
context.Load(list);

CamlQuery query = new CamlQuery();
query.ViewXml = "";
ListItemCollection cols = list.GetItems(query);
context.Load(cols);

ListItem item = cols.GetById(1);
context.Load(item);

context.ExecuteQuery();
Response.Write(item["Name"].ToString());

Wednesday, May 11, 2011

Feel Good about myself

This is my first attempt to take MS 70-667 SharePoint configuration and Maintenance exam on "MeasureUp.com".When I test my knowledge on these topic on trial test engine page on my attempt,I have passed with 80%.I am really feel good about myself.:)-

Monday, May 09, 2011

SharePoint Claim based Identity

Assume you have an SharePoint web application which build on "Claim based Authentication"

When user requested the page or Sharepoint documents using web browser,SharePoint will check the user has been authorised or not.
If it is not authorised,It will send back to user with requested URL,in turn user's request will be redirected to "Identity Provider".It can be Active Directory or "ASP.NET Membership Provider".
Once your credentials are validated by "Identity Providers" you will be given a token to which will allow your request to be authenticated by SharePoint.

Friday, May 06, 2011

Listing all Folder in SharePoint 2010

To list all the "Folders" in a site or web in SharePoint 2010
SPSite site = SPContext.Current.Site;
            SPFolderCollection cols =  site.OpenWeb().Folders;
            foreach (SPFolder folder in cols)
            {
                ListBox1.Items.Add(folder.Name.ToString());
            }

Thursday, May 05, 2011

WCF error in SharePoint 2010



I was about to consume the SharePoint 2010 List WCF service on my web application using jSon.
When I tried this link http://serverName:8056/_vti_bin/ListData.svc
on my sharepoint environment,I got this error saying "Could not load type "System.Data.Services.Providers.IDataServiceUpdateProvider".

To resolve this issue
Apply : the batch update
http://support.microsoft.com/kb/976127

Wednesday, May 04, 2011

Downloading the SharePoint Document

Recently,a strange scenario in SharePoint 2010 development I faced.
I created a Visual WebPart with sandbox solution based to let user download the files from the SharePoint Document Library.
Labour the lines of code to get reference of the SPFile from the current web context.
Reading and Writing the file contents into streams to let user to download the file as soon as they clicked it on the "Download" link.It will prompts the "File Download Dialog box".
I deployed it on the sharepoint development environment it just works fine.
Later,I came to know that webpart is not allowing the end user to download.
Again I checked the same webpart performance and put optimised looping and disposing the objects verily stated manner.
Its works fine as I expected.But When I deployed it on SharePoint Server,I faced the same problem when user accessing the page.
When end user clicks the link "Download",Browser redirect to "Forbidden page".

Finally I have concluded the user is only "Reader" permission group.

Simply added RunWithElevatedPrivileges
Its works fine for all user group permission.
protected void Button1_Click(object sender, EventArgs e)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
FileAction();
});
}
protected void FileAction()
{
SPWeb site = SPControl.GetContextWeb(Context);
SPFile spFile = site.GetFile(site.Url + "/DocLibrary/" + "1.txt");
// Above line for clarity purpose hard coded.You can read the file name from the //library.My requirement there was only one file.
FileStream fs = new FileStream("C:\\Windows\\Temp\\tempContents.txt", FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(spFile.OpenBinary());
bw.Close();
fs.Close();

using (FileStream sm = File.Open("C:\\Windows\\Temp\\tempContents.txt", FileMode.Open))
 {
using (StreamReader sr = new StreamReader(sm))
{
Response.AppendHeader("Content-Disposition", "attachment; filename =" + spFile.Name);
Response.ContentType = "text/plain";
using (StreamWriter sw = new StreamWriter(Response.OutputStream))
{
sw.Write(sr.ReadToEnd());
}
}
sm.Close();
Response.Flush();
Response.Close();
}
}