Monday, November 21, 2011

SharePoint Get list item parent folder

thanks to author @ http://blogs.tamtam.nl/appie/2009/02/23/Getting+ParentFolder+From+A+Custom+List.aspx

we can use the following method to get parent folder of listitem


static SPFolder GetParentFolder(SPListItem itemToFind, SPFolder folder)
{
      SPQuery query = new SPQuery();
      query.Folder = folder;
      SPListItemCollection items = itemToFind.ParentList.GetItems(query);
     
      foreach (SPListItem item in items)
      {
            if (item.ID == itemToFind.ID)
            {
                  return (folder);
            }
            if (item.Folder != null)
            {
                  SPFolder resultFolder = GetParentFolder(itemToFind, item.Folder);
                  if (resultFolder != null)
                  {
                        return (resultFolder);
                  }
            }
      }

      return (null);
}


So adding that function allows you to get a parentfolder with:

SPFolder parentFolder = GetParentFolder(item, null);







Thursday, November 17, 2011

Get only folders from SharePoint list

thanks to author @ http://www.ktskumar.com/blog/2009/07/retrieve-all-folders-from-list/


the trick is FSObjtype=1.
Use this while querying the list

query.Query = “<Where><Eq><FieldRef Name=’FSObjType’/><Value Type=’Lookup’>1</Value></Eq></Where>”; 


Monday, November 14, 2011

SharePoint 2010 Empty Recycle Bin


Thanks to author @

http://dhireny.blogspot.com/2010/06/empty-all-items-from-sharepoint-recycle.html#!/2010/06/empty-all-items-from-sharepoint-recycle.html

the trick is
goto recylebin page, then paste this in addressbar textbox in browser

javascript:emptyItems();


then press enter, thats it









SharePoint 2010 + webpart page with quick launch

thanks to author @ http://pscave.blogspot.com/2010/10/show-quick-launch-on-sharepoint-2010.html

the steps are

Delete the following from your webpart page

1.
         < asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server"></asp:Content>

2.
< asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"></asp:Content>

3.
< style type="text/css">
body #s4-leftpanel {
display:none;
}
.s4-ca {
margin-left:0px;
}
</style>




Friday, October 14, 2011

CAML query on number field with BeginsWith--Work around

I faced problem when I tried to filter my list with BeginsWith operator on number column. It may treat the condition as "Eq" because of the Data type Number.

The work around I found is , create another column as Calculated. The twist here is , again it considers the condition as "Eq". So the formula i used is "=CONCATENATE("A",Column1)". Select the data type of Calculated field as Single Line Of Text.

Now my condition to filter is  <BeginsWith> <Value>A + our Field Value</value>

My Code is here:-

Create Calculate Field
strDispName = lstFAS.Fields.Add(strDeptColName + "Dup", SPFieldType.Calculated, false);
                fldCalc = (SPFieldCalculated)lstFAS.Fields[strDeptColName + "Dup"];
                fldCalc.Formula = @"=CONCATENATE(""A"",[Department])";
                fldCalc.Update();


Query
SPQuery queryFAS_ByCondition = new SPQuery();
                        queryFAS_ByCondition.Query = string.Format("<Where><BeginsWith><FieldRef Name='DepartmentDup' /><Value Type='Text'>{0}</Value></BeginsWith></Where>",
                                                               "A"+lstItemFASSiteFinder_ByID.Title);


The code may look ugly, but hey it worked for me.

happy coding....:-)

Thursday, September 15, 2011

SharePoint Foundation + edit/update excel files programatically in Document library

Voila.....finally its working.....:-)

After googling for hours together finally found the appropriate codes/links

my requirement is quite simple (???)

update/edit the excel files in my document library programatically. Sounds simple.....huh?

The real problems occur when we start working towards the requirement.

problem 1.   Server will not have excel dlls to work with.
problem 2.  Jet/ACE drivers giving lot of error while using  (using OLEDB)
Problem 3. Cannot trust third party dlls

Finally microsoft/other sites shed some light on how to use Open XML for this scenario.

http://howtosharepoint.blogspot.com/2010/05/programmatically-edit-and-save-file.html

http://msdn.microsoft.com/en-us/library/ee956524.aspx


I've created one class with the methods given in Open XML.

Created one method as below

public static MemoryStream UpdateMe2(MemoryStream memStr, string sheetName, string strCellName, string strVal)
       {

           using (SpreadsheetDocument document = SpreadsheetDocument.Open(memStr, true))
           {
               WorkbookPart wbPart = document.WorkbookPart;

               UpdateValue(wbPart, sheetName, strCellName, strVal, 0, true);
               return memStr;
           }

           return null;
       }




Tuesday, September 13, 2011

SharePoint Timer jobs Access denied on feature activation

Thanks to Kshitijb  @
http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/f41810ec-2348-436d-a574-c29656f3a567/

Refer this link for detailed explanation.
http://stackoverflow.com/questions/1036589/problem-in-creating-timer-job


The problem is , my feature has scope site.

Timerjob's feature Scope should be web application or Farm.

It solved my problem.

BUT I do remember, I have some timer jobs with scope web and are running fine. (This is NOT recommended)