Monday, January 18, 2010

SharePoint 2010 (Beta) Training Kit

download it from http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=f1599288-a99f-410f-a219-f4375dbe310c

Monday, January 11, 2010

Completely Remove Left Navigation from v4. master Page

hi,

yesterday i was goign through the htmls of master page, the big difference I found is tables has been replaced by <Div>. The team gave OOB minimal v4.0 Master page also v3.0 master pages are present.

I was trying to remove left navigation completely, after investing some time below are the steps to do it -
look for div id="s4-leftpanel" class="s4-notdlg"
right click on it, select tag, remove that complete portion. you just removed the left navigation..every thing Quick launch,Recycle Bin. But to work the master page properly add the removed contentPlace Holders again, below are the contentPalce holder which should be added at minimum to work it proper -
<asp:ContentPlaceHolder id="PlaceHolderLeftNavBarDataSource" runat="server" />
<asp:ContentPlaceHolder id="PlaceHolderCalendarNavigator" runat="server" />
<asp:ContentPlaceHolder id="PlaceHolderLeftActions" runat="server"></asp:ContentPlaceHolder>
<asp:ContentPlaceHolder id="PlaceHolderLeftNavBarTop" runat="server"/>
<asp:ContentPlaceHolder id="PlaceHolderLeftNavBar" runat="server"></asp:ContentPlaceHolder>
<asp:ContentPlaceHolder id="PlaceHolderQuickLaunchTop" runat="server"></asp:ContentPlaceHolde>

now to use the complete space occuiped by left nagivation ->
Div with ContentID = MSO_ContentTable has a style class s4-ca which sets left margin to 115, make it to 0 and you are done.
it should look like -
div class="s4-ca s4-ca-dlgNoRibbon" id="MSO_ContentTable" style="margin-left:0px"

Done..use compelet space now!!

Friday, January 8, 2010

Silverlight ClientObject Model, uploading File to Document Library

Hi,
I want to share the new learning with all of you,I was trying to upload file to document library suing client object model. the client Object Model for Managed code gives option for 'SavebinaryDirect()' but no such thing for silverlight, then how to achieve the same goal using silverligt. hey below is the code -

private void uploadFileToDocumentLibrary(string fileName, byte[] fileContent)
{
ClientContext cnt = ClientContext.Current;

listForUpload = cnt.Web.Lists.GetByTitle("Redmond");

this.Dispatcher.BeginInvoke(delegate()
{
cnt.Load(listForUpload);
cnt.Load(listForUpload.RootFolder);
cnt.Load(listForUpload.RootFolder.Files);
cnt.ExecuteQueryAsync(succeedUploadFileListner, failureUploadFileListner);
});

}


private void succeedUploadFileListner(object sender, ClientRequestSucceededEventArgs e)
{

// byte[] dataArray;
Microsoft.SharePoint.Client.File file1 = listForUpload.RootFolder.Files[0];
this.Dispatcher.BeginInvoke(delegate()
{
byte[] dataArray = allFiles[lstFiles.Items[0].ToString()];
FileCreationInformation file = new Microsoft.SharePoint.Client.FileCreationInformation();

file.Content = dataArray;
file.Overwrite = true;
file.Url = lstFiles.Items[0].ToString();
listForUpload.RootFolder.Files.Add(file);
listForUpload.Update();
ClientContext.Current.ExecuteQueryAsync(s1, f1);


});


}

private void s1(object sender, ClientRequestSucceededEventArgs e)
{
this.Dispatcher.BeginInvoke(delegate()
{
MessageBox.Show("File Uploaded");
});
}
private void f1(object sender, ClientRequestFailedEventArgs e)
{
this.Dispatcher.BeginInvoke(delegate()
{
if (string.IsNullOrEmpty(e.Message))
{
MessageBox.Show(e.Exception.InnerException.Message);
}
else
{
MessageBox.Show(e.Message);
}
});
}
Key things are - First list should be loaded, then you can access .rootFolder and add files to it. this is the reason why I am writting actual file upload code in succeddLisnter of List load.

File.Url is file name and list.rootFolder gives the address like http:///.

In this snippet the error which bugged me most is 'Remote server returned error:Not found'. this error comes when the requested object is not reachabel, reasons could be typo error or invalid url or like in my case I was giving file.Url = "http://... full url where as it should be file Name like try.txt.

the second error I found at I was trying to add files before list lost, the moment I replaced to add file code to succeddLisnter it worked like charm. try this

Cheers :)

Friday, January 1, 2010

Client OM,Delete multiple items from Document Library Asynchrously[silverlight]

hi All,
Very happy new year to all of you. first day of 2010 gave me new information while working with client object model asynchrnously, which I want to share with all of you.

Below is the code to delete obect from list, using Client OM ->
private void btn_Delete(object sender, RoutedEventArgs e)
{

foreach (GridData data in dataSource)
{
if (data.IsChecked)
{

if (!(selectedItems.ContainsKey(data.DocID)))
{

selectedItems.Add(data.DocID, data.DocUrl);
}
}
}
if (selectedItems.Count > 0)
{
foreach (var grd in selectedItems)
{
deleteItem(grd.Key, grd.Value);
}

}

else
{
MessageBox.Show("Please select atleast one item");
}
}
private void deleteItem(string itemID, string itemUrl)
{

if (cnt == null)
{
throw new Exception("connection failed");
}
else
{

List olist = cnt.Web.Lists.GetByTitle(listName);
ListItem item = olist.GetItemById(itemID);
item.DeleteObject();
this.Dispatcher.BeginInvoke(delegate()
{
cnt.Load(olist, list => list.Title);

cnt.ExecuteQueryAsync(delete_succeedListner, delete_failureListner);
});
}
}
private void delete_succeedListner(object sender,ClientRequestSucceededEventArgs e)
{

this.Dispatcher.BeginInvoke(delegate()
{
MessageBox.Show("Item deleted");
});

}

this is perfactly fine to delete single item from list. Why I am saying so? just look at code once again, actually item is getting deleted at succeddListner, where nothing otherthan messageBox, which means it will always delete the last item from for loop (where I am caling deleteItem()), it will loose all the previous information and will not work as in synchrouse way. what to do for multiple delete in this case? ideally in succeedLisnter, when one item is deleted. deleteItem() should be invoked again to delete the second item, and so on.check the below code for multiple item delete -
private void btn_Delete(object sender, RoutedEventArgs e)
{

foreach (GridData data in dataSource)
{
if (data.IsChecked)
{

if (!(selectedItems.ContainsKey(data.DocID)))
{

selectedItems.Add(data.DocID, data.DocUrl);
}
}
}
if (selectedItems.Count > 0)
{
string tobeDeleted_key = string.Empty;
string tobeDeleted_value = string.Empty;


tobeDeleted_key = selectedItems.First().Key;
tobeDeleted_value = selectedItems.First().Value;
deleteItem(tobeDeleted_key, tobeDeleted_value);


}

else
{
MessageBox.Show("Please select atleast one item");
}


}
private void deleteItem(string itemID, string itemUrl)
{
cnt = new ClientContext(serverUrl);
if (cnt == null)
{
throw new Exception("connection failed");
}
else
{
MessageBox.Show(itemUrl + " From listName " + listName);
oList = cnt.Web.Lists.GetByTitle(listName);
ListItem item = oList.GetItemById(itemID);
item.DeleteObject();
oList.Update();
this.Dispatcher.BeginInvoke(delegate()
{
cnt.Load(oList, list => list.Title);
cnt.ExecuteQueryAsync(delete_succeedListner, delete_failureListner);
});
}
}
private void delete_succeedListner(object sender,ClientRequestSucceededEventArgs e)
{
string tobeDeleted_key = selectedItems.First().Key;
this.Dispatcher.BeginInvoke(delegate()
{
MessageBox.Show("Item deleted");
selectedItems.Remove(tobeDeleted_key);
if (selectedItems.Count > 0)
{
string tobeDeleted_value = string.Empty;
tobeDeleted_key = selectedItems.First().Key;
tobeDeleted_value = selectedItems.First().Value;
deleteItem(tobeDeleted_key, tobeDeleted_value);
}
else
{
fillDataGrid();
}
});

}

Cheers!!