About Me

My photo
a Dynamic and Energetic guy.....

Tuesday, July 28, 2009

Sharepoint 2010 Overview

It's time to have a look new features that we want in sharepoint !!!

  1. Look & Feel (Ribbon Control)
  2. Multi document Checkout + avoid from post backs
  3. Nice pop-up windows than response.redirects J
  4. Direct uploading & showing images from your computer to sharepoint
  5. SilverLight webpart
  6. Nice themes like "PowePoint Theme"
  7. Visio services running with sharepoint services (Visio is not necessary)
  8. Fully rich Sharepoint Designer
  9. Entities to connect SQL,LOB with Edit/Delete functions (OOB)
  10. Direct connect to the office tools like Office 2010 with a click J

Change the data in a Infopath form library programatically

First we have to take care few things
(1) We should allow unsafe upates = true
(2) We should check out the file




(3) We cant use our item update event inside "SPSecurity.RunWithElevatedPrivileges(delegate.."
Code is simple

SPSite objSite = new SPSite("http://sharepointsvr:123/");
SPWeb objWeb = objSite.RootWeb;
SPFolder oFolder = objWeb.GetFolder("Participant");
SPFileCollection collFiles = oFolder.Files;
objWeb.AllowUnsafeUpdates = true;

foreach (SPFile oFile in collFiles.Folder.Files)
{
SPListItem oListItem = oFile.Item;
oListItem.File.CheckOut();
oListItem["ProgramaticField"] = "Chanaka has done it";
oListItem.SystemUpdate();
oListItem.File.CheckIn("chana did");
}

Thursday, July 23, 2009

Sharepoint hints

Web Services that we are getting
http://sharepointsvr:15613/_vti_bin/lists.asmx


How I enable Anonymous+Access
http://2.bp.blogspot.com/_emfxSHRT-kE/R6PByOkwg5I/AAAAAAAAAFc/HXGsfUuTtqk/s1600-h/Anonymous+Access.JPG

Get the response of web request programatically

StreamReader responseReader = null;
HttpWebRequest httpRequest = null;
httpRequest = (HttpWebRequest)WebRequest.Create("http://172.21.0.60:8034/");
httpRequest.Method = "GET"; // User get data

HttpWebResponse webResponse = null;
webResponse = (HttpWebResponse)httpRequest.GetResponse();
Encoding enc = Encoding.Default;
responseReader = new StreamReader(webResponse.GetResponseStream(), enc);
String temp = responseReader.ReadToEnd();

Wednesday, July 22, 2009

Infopath data retrieve with Sharepoint

SPSite objSite = new SPSite("http://sharepointsvr:123/");
SPWeb objWeb = objSite.RootWeb;
SPList objList = objWeb.Lists["Participant"];
SPQuery objQuery = new SPQuery ();
SPListItemCollection objCollection = objList.GetItems(objQuery);
SPListItem objItem = objCollection[0];
SPFile objFile = objItem.File;
byte[] xmlFormData = objFile.OpenBinary();
XPathDocument ipForm = null;
using (MemoryStream ms = new MemoryStream(xmlFormData))
{
ipForm = new XPathDocument(ms);
ms.Close();
}
XPathNavigator ipFormNav = ipForm.CreateNavigator();
XPathNavigator nodeNav = ipFormNav.SelectSingleNode("/my:myFields/my:fldFamilyName", GetFormNSM(ipForm));
string strValue = nodeNav.InnerXml;
Response.Write(strValue);


//XML Namespace Creator

private XmlNamespaceManager GetFormNSM(XPathDocument ipForm)
{
const string strMYNamespacePrefix = "my";
const string strMYNamespaceURI = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-06-25T10:50:10";

const string strDIRNamespacePrefix = "d";
const string strDICNamespaceURI = "http://schemas.microsoft.com/sharepoint/soap/directory/";


XPathNavigator formAccess = ipForm.CreateNavigator();
XmlNamespaceManager namespaceMngr = new XmlNamespaceManager(formAccess.NameTable);
namespaceMngr.AddNamespace(strMYNamespacePrefix, strMYNamespaceURI);
namespaceMngr.AddNamespace(strDIRNamespacePrefix, strDICNamespaceURI);

return namespaceMngr;
}

Monday, July 13, 2009

RunWithElevatedPrivileges in sharepoint


When we try to get data from a document library that is not assigned for current user, we are getting this error.

Solution is:::::

SPSecurity.RunWithElevatedPrivileges(delegate()
{
//any code that we have to use
});


Sometimes even we add this delegate still it's not working.
That's because the object we are using made without elevated privileges.
(Ex:- We are creating SPWeb under the delegate, but the SPSite(parent object) object is outside the delegate, then we won't get chance to access data)

My Masters