5 October 2011

Accessing web service in SharePoint Online (Cloud –Office 365)

Accessing web service in SharePoint Online (Cloud –Office 365).
It was an end of a tiring day where I tried to consume a web service in the SharePoint online and finally I succeeded. Thanks to Sajid Mohammad who redirected me to the blog of Wictor , and a great thanks  to him for providing  MsOnlineClaimsHelper class.Un like in  Wictor’s  example  my requirement was to consume a web service.
So All need to do is that assign my webservice’s cookicontainer class to the claims helper’s cookiecontainer as follows.
objLists.CookieContainer = claimsHelper.CookieContainer;
The whole code will look like below.
try
{
MsOnlineClaimsHelper claimsHelper = new MsOnlineClaimsHelper("http://......./teamsite/_vti_bin/Lists.asmx", @"<username>", "<password>");
FileGET.Lists objLists = new FileGET.Lists();
objLists.CookieContainer = claimsHelper.CookieContainer;
objLists.Url = "http://dev22.sharepoint.com/TeamSite/_vti_bin/Lists.asmx";
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
XmlNode ndListItems = objLists.GetListItems("test", null, null, null, null, ndQueryOptions, null);
XmlTextReader reader = new XmlTextReader(ndListItems.OuterXml, XmlNodeType.Element, null);
//to display in my windows application
DataSet ds = new DataSet();
ds.ReadXml(reader);
dataGridView1.DataSource = ds.Tables[1];
}
catch (Exception ex)
{
 MessageBox.Show(ex.ToString());
}

----------------------------------------------------------------------------------------------------------------------------
Note : In case you are calling this with in a firewall dont forget to put the following ahead of the script.

if (WebRequest.DefaultWebProxy.Credentials == null)WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;

1 September 2011

File Tagging Folks + Taxonomy = Folksonomy

File tagging folks+ taxonomy= folksonomy.
Recently I came across a scenario where individual files need to be tagged by multiple people. So that tag based routing or audience targeting can be done. My initial idea was to add taxonomy to the file.
Using managed metadata column.
But here arise a problem that it is difficult to track that who tagged. The Alternative was to take out the tagging mechanism from the content, but still use the folksonomy taxonomy feature extent to a different list.
The approach is as follows:
Create a separate list with columns like file URI, tag, user who tagged it. There should be a mechanism to make the folksonomy to add to the term store on identification  of new term.my idea here is to travers e the existing taxonomy tree with a like search, or similar. And add valid terms, So added folksonomy will be emerged as taxonomy and help in the file tagging and classification.
Another issue was how to do automatic file tagging, this means by reading the content how a document can be tagged. This can be achieved to an extent only; the base to start with this is the term store management only. By traversing the terms in the hierarchy and hitting no of counts of the same in the file a file can be given an automatic tag. But this reading process may end up with deterministic result too.




12 August 2011

Kind a Gotcha

Problem : Save the site as a template missing.
Resolution : If you have “SharePoint Server Publishing” feature turned active in a SharePoint site (this is a web feature). You cannot Save the site as a template. This is because SharePoint 2010 by default stops creating site definition of a publishing site A Publishing site may have interdependencies that cannot be incorporated in a template when a template is getting created.
Problem : You are geting error while creating a search center site.
 Please check In the site collection fetures "SharePoint Server Publishing Infrastructure is Active", Because when you use a site creation with a new site template that use a diffrent master page , this feature need to be activated, otherwise publishing of the master page wont happen and hence fail the site creation.
Problem :
You are getting message "The operation could not be completed" when you connect to SharePoint from InfoPath.
Reason : The Site You are connecting missing a Root Site.InfoPath works only when you have a root site in the site collection.
Resolution : Create a Root Site in the site collection.
Problem: Error at Microsoft.Office.Server.Administration.UserProfileApplicationProxy.get_PartitionIDs() and in the error log.Current time is '2012-04-10T13:16:33.496Z' and allowed clock skew is '00:05:00'.
Resolution: All servers in the Farm should have the same time.Check all the servers in the farm have the same clock timing and in synch.

Problem: 503 errors after the credential change.
Resolution: in the iis in the credential reset the password of the app domain account.
Problem:The CLR has been unable to transition from COM context 0x1bd54fb0 to COM context 0x1bd55200 for 60 seconds. The thread that owns the destination

Resolution:This is a configuration change required issue. and need to set in the project propertiesDebug > Exceptions > Managed Debug Assistants (MDA), and then unchecking the ContextSwitchDeadlock option

Problem:Operation is not valid due to the current state of the object
Resolution:In valid assembly reference , comma missing or public key not correct
Problem:Object reference not set to an intance of object - while creating site collection using object model.
Resolution:Use web service to create site colloction
Problem:CREATE DATABASE permission denied in database 'master'.
Resolution:Add the app pool a/c as database creater in sql server.
Problem:While uploading file while migration after a limit getting the error as follows
The URL 'DocVault Library/mail_Sending_wf.wsp' is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web.
Resolution:This issue is due to the wrong version of sql server integarted with the share point.
Express edition of sql server does not support files beyond a limt.
Problem:'AllDocStreams_CI' in database 'WSS_Content_44444' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.
Resolution:This issue was due to the database growth parameters are not properly set in the development database server.Resolved by setting the correct version of database with proper growth ratio.
Problem:Diffrence of situvation using Static Name and Name with list.
Resolution:Static name will work with the list item , while Name works with after and before properties.
names are used insted of static Name in the code.
Problem:The field you are tying to update is read only,while trung to update Created By(Author).
Resolution:Code defect which is fixed by overriding the normal sharepoint default setting for the Author.
Problem-Resolution:UTC date need to be used while Updating from event reciver.

Problem:Trying to use a SPWeb object that has been closed or disposed and is no longer valid
Resolution: insted of using (SPWeb myWeb = SPContext.Current.Web)  use
Problem: Application error on the webpart page.
Resolution:Put ?content=1 to show which webpart is giving error or fix.
using (SPWeb myWeb = SPControl.GetContextSite(Context).OpenWeb()) (never close SPContext.Current.Web)

Problem: Not able to open webpart page.
Resolution: put <url>?content=1 and then edit and remove errored webpart
or if subsite is not able to open use
_layouts/spcontnt.aspx?url=/<site>/<subsite>/default.aspx to get the web part page of the subsite , edit and edit and remove errored webpart.
or finally try reset the page to site defnition in the sp designer.

Problem: People Search not returning result for https site
Resolution: for https sps3s:// and for http sps3:// on the search location of mysite.
Also reset the crawl and do full crawl.

Problem: People search people image url not set.
Resolution: use powershell script to reset the picture url of the profile for all profiles.

Problem: The text box disabled while adding web reference
Resolution:Add ?wsdl at the end or click the service discription (up to asmx does not create the proxy , need the wsdl)

10 August 2011

Mobile Configuration for SharePoint2010

“compat.browser” within the server’s IIS directory will be "\inetpub\wwwroot\wss\VirtualDirectories\80\App_Browsers\compat.browser").
The configuration file for sharepoint 2010 with Mobiles. For eg. The IsMobileDevice attribute of that mobile browser when set to FALSE will
cause SharePoint to bypass the mobile view for that browser.”

Note that if you do any modification with sharepoint designer to a site and found that *.browser file got duplicated in another folder , you need to delete this folder

7 August 2011

List web service and Copy web service to down load files from a Folder in SharePoint

/*It is a very common requirement that to down load the files from a folder from a sharepoint library using web service.The following code uses two inbuilt web services of sharepoint two down load files using webservice. This code can be used to create a console application that can be scheduled using a windows service to have scheduled transfer from Sharepoint*/


using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.IO;using System.Xml;using System.Configuration;using System.Data;namespace
{
FromSharePointclass Program{

{
static void Main(string[] args)try{
FileGET.
objLists.Credentials = System.Net.


objLists.Url = sitePath +


ndQueryOptions.InnerXml =
Lists objLists = new FileGET.Lists();CredentialCache.DefaultCredentials;string sitePath = ConfigurationManager.AppSettings["SitePath"].ToString();string destPath = ConfigurationManager.AppSettings["DestinationPath"].ToString();"_vti_bin/Lists.asmx";XmlDocument xmlDoc = new System.Xml.XmlDocument();XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");string.Format("<Folder>{0}</Folder>", ConfigurationManager.AppSettings["SourcePath"].ToString());XmlNode ndListItems = objLists.GetListItems("Library", null, null, null, null, ndQueryOptions, null); // you can change the document library name to your custom document library name

ds.ReadXml(reader);

{

{

CopyLIST.
myCopyService.Url = sitePath +
myCopyService.Credentials = System.Net.


CopyLIST.
CopyLIST.
XmlTextReader reader = new XmlTextReader(ndListItems.OuterXml, XmlNodeType.Element, null);DataSet ds = new DataSet();if (ds.Tables.Count > 1)foreach (DataRow dr in ds.Tables[1].Rows)string fpath = dr["ows_FileRef"].ToString().Substring(dr["ows_FileRef"].ToString().IndexOf("/"));Copy myCopyService = new CopyLIST.Copy();"_vti_bin/copy.asmx";CredentialCache.DefaultCredentials;string webURL = sitePath.Substring(0, sitePath.IndexOf("sites/") + 5);string copySource = webURL + fpath;FieldInformation myFieldInfo = new CopyLIST.FieldInformation();FieldInformation[] myFieldInfoArray = { myFieldInfo };byte[] myByteArray;// Call the web service
uint myGetUint = myCopyService.GetItem(copySource, out myFieldInfoArray, out myByteArray);// Convert into Base64 String
base64String =
string base64String;Convert.ToBase64String(myByteArray, 0, myByteArray.Length);// Convert to binary array
byte[] binaryData = Convert.FromBase64String(base64String);// Create a temporary file to write the text of the form to
string tempFileName = destPath + @"\"+ dr["ows_LinkFileName"].ToString();// Write the file to temp folder
fs.Write(binaryData, 0, binaryData.Length);
fs.Close();
}
}
}

{


}
}
}
 
}
 
FileStream fs = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite);catch (Exception ex)Console.WriteLine(ex.ToString());Console.Read();

Copy Files To SharePoint from Local Folder Using OOB Copy WebService

/*It is very common requirement that you need to upload files from a folder to Sharepoint. The OOB Copy web service can be used for the same,The below code can be used to create a console application that can be used to schedule transfers*/

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Configuration;namespace
{
ToSharePointclass Program{

{
static void Main(string[] args)try{
CopyLIST.
myCopyService.Url =

string passWord = ConfigurationManager.AppSettings["Password"].ToString();
System.Net.NetworkCredential nc2 = new System.Net.NetworkCredential(userID, passWord);*/
Copy myCopyService = new CopyLIST.Copy();ConfigurationManager.AppSettings["SitePath"].ToString() + "_vti_bin/Copy.asmx";/*string userID = ConfigurationManager.AppSettings["UserID"].ToString();myCopyService.AllowAutoRedirect =
myCopyService.PreAuthenticate =
myCopyService.Credentials = System.Net.


CopyLIST.
CopyLIST.


{



{


lcopyDest[0] = copyDest +


{
true;true;CredentialCache.DefaultCredentials;string copySource = ConfigurationManager.AppSettings["SourcePath"].ToString();string copyDest = ConfigurationManager.AppSettings["DestinationPath"].ToString();FieldInformation myFieldInfo = new CopyLIST.FieldInformation();FieldInformation[] myFieldInfoArray = { myFieldInfo };byte[] myByteArray;if (System.IO.Directory.Exists(copySource))string[] files = System.IO.Directory.GetFiles(copySource);string[] lcopyDest = new string[1];foreach (string s in files)int inv = s.LastIndexOf(@"\");string flname = s.Substring(inv + 1);@"\" + flname;string src = copySource + @"\" + flname;using (FileStream fileStreamSource = new FileStream(src, FileMode.Open, FileAccess.Read))// Read the source file into a byte array.myByteArray =



{


{

}
numBytesRead += n;
numBytesToRead -= n;
}
numBytesToRead = myByteArray.Length;

{
}
}
CopyLIST.
CopyLIST.
new byte[fileStreamSource.Length];int numBytesToRead = (int)fileStreamSource.Length;int numBytesRead = 0;while (numBytesToRead > 0)int n = fileStreamSource.Read(myByteArray, numBytesRead, numBytesToRead);if (n == 0)break;if (myByteArray.Length > 0)CopyResult myCopyResult1 = new CopyLIST.CopyResult();CopyResult[] myCopyResultArray = { myCopyResult1 };try{

myFieldInfoArray, myByteArray,

{


{


{


myCopyResultArray[idx].DestinationUrl);
}
uint myCopyUint = myCopyService.CopyIntoItems(copySource, lcopyDest,out myCopyResultArray);if (myCopyUint == 0)int idx = 0;foreach (CopyLIST.CopyResult myCopyResult in myCopyResultArray)string opString = (idx + 1).ToString();if (myCopyResultArray[idx].ErrorMessage == null)Console.WriteLine("Copy operation " + opString +"completed.\r\n" + "Destination: " +else{


myCopyResultArray[idx].ErrorMessage +

}
idx++;
}
}
}

{


}
}
}
}

{


}

}
}
}
Console.WriteLine("Copy operation " + opString +" failed.\r\n" + "Error: " +"\r\n" +"Code: " + myCopyResultArray[idx].ErrorCode);catch (Exception exc)Console.WriteLine(exc.ToString());Console.Read();catch(Exception ex)Console.WriteLine(ex.ToString());Console.Read();

30 April 2011

Gotchas while Updating date field while restoring item from recycle bin Moss 2010

Recently I came across a scenario in which I need to restore a document which is send to recycle bin by a retention process. And I need to reset the date field that is reference for retention, so that it will again fall in the retention cycle.
So How should I know in the event receiver that the ‘ItemAdding” is happening when the item is newly added or item is being restored. I will know this by checking the ListitemID property inside the “ItemAdding” event , If ListItemId is non zero then it is fired from restore. But ‘ItemAdding” event will not allow you to change any property while the item is getting restored.
So I need to relay on the ‘Itemadded” Event. So here how should I check that The event is fired from restore or while ‘ItemAdding” initially. I checked the current date with the created date of the list item for this. If they are different then the event is being fired from the restore.(the business logic is that you need to set min 1 day retention period).And ‘Itemadded” event is the only place I can reset my datefield refered by the retention process.
I faced another issue here, if your server is in a different time zone than the client you cannot update this date field (need to use ISO format) with datetime.now. You need to use datetime.utcnow.
But if the server is in the same time zone You can either use DateTime.Nowor DateTime.UtcNowto update the date field.
So I done similar below to deploy the code in the server that reside in a different time zone.
public override void ItemAdded(SPItemEventProperties properties)
        {
                base.ItemAdded(properties);
                EventFiringEnabled = false;
                SPListItem currentItem = properties.ListItem;
                DateTime created = (DateTime)currentItem[CREATED];
                //Compare the Created Date and The Present datetime. If Created date is not same as current datetime, it means the docuemnt was restored.
               //While restoring retention date is set to the current utc date, so that it will fall back to recycle bin  in the next retention stage
                int recycle = DateTime.Compare(created.Date, System.DateTime.Now.Date);
                if (recycle != 0)
               { //Update The UploadedDate to Current Date Time
                    DateTime today = DateTime.UtcNow.Date;
                    Util.LogInfo("UTC", SPUtility.CreateISO8601DateTimeFromSystemDateTime(today));
                    currentItem[RET_REF_DATE_STAT] = SPUtility.CreateISO8601DateTimeFromSystemDateTime (today);
currentItem.Update();
}
 }