Friday, May 29, 2009

How to find page/site customization status – Part 2 – with the help of SharePoint object model

I know that if I find my required data/information from SharePoint database then there must be some way to find same thing from object model. So I started debugging SPFile object and tried to see what are the properties exposed by object model, but I didn’t see any properties from code, then I have found some hidden properties which match with ALLDOCS table schema, properties names are "vti_hasdefaultcontent", "vti_setuppath", so after using those hidden SPFile properties, I got my results which match with query results,

Example Code:



SPFile objFile;

string bDefaultContent = (string)objFile.Properties["vti_hasdefaultcontent"];

string strSetupPath = (string)objFile.Properties["vti_setuppath"];

if (strSetupPath == null && bDefaultContent == null)

{

//If code executed and comes into this loop then current Page/File status is customized

//then I can take objFile.File and objFile.URL values

}

Reference Links:



I have found one hidden property name from object model for checking page/site customization

http://stsadm.blogspot.com/2007/09/re-ghosting-pages.html

Hidden Property name from file object

http://www.eggheadcafe.com/conversation.aspx?messageid=29277607&threadid=29254168

Comments are always welcome!!!

How to find page/site customization status – Part 1 – with the help of Content Database Schema

Till now, that was one of my toughest assignment, my requirement was to find all pages which customized or changed from SharePoint designer, visual studio and any editor tool, when I started working on the requirements, I thought that I can easily find page customized status (ghosted/unghosted) from SharePoint object model - page CustomizedPageStatus enumeration, but that flag gave me wrong value, I mean, I can’t see my pages as customized which I created from SharePoint Designer.

 

At one time, I don’t know what to searched in Google, because I tried all combination of search query to get some useful output, but It didn’t bring me anything, all search result gave me idea and links about ghosting, how to customize page and how to reset to site definition from SharePoint designer, etc…..

 

After some time, I have found one link which says how to deal and work with SharePoint content database, so I started playing around with content database and I have found out that I can write a query which will give me page customization status, SharePoint stores all the information into database, “ALLDOCS” table has all information regarding page size, version, attached list, modified user, time and many more ….

 

By looking into schema for ALLDOCS table, I created database query and finally I got my result and I was so happy to see the result :)

 

Below is sample query which will give us all the pages which customized/created from SharePoint Designer, Visual Studio or any other editor tool.

 

QUERY:

 

SELECT

W.Title, W.FullURL,

D.DirName + '/' +  D.LeafName as pageName,

TimeLastModified as ModifiedTime,

*

FROM

Alldocs  D With (NoLock)

JOIN Webs W With (NoLock)

On W.ID=D.WebID

WHERE

D.hasstream = '1'

and D.extension  = 'aspx'

and D.iscurrentversion = '1'

and D.setuppath is NULL

 

Reference Links:

 

ALLDOCS table schema – columns and its description

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

 

Database table information to find page customized status

http://sky-soft.net/SkySoft/Documentation/WSS/WSSv3Notes.htm

 

Information about SharePoint content database

http://www.sharepointu.com/ethan/archive/2007/09/16/inspecting-the-sharepoint-content-database.aspx

 

Query to find list of documents from site collection

http://stackoverflow.com/questions/213801/sharepoint-2007-sql-query-to-find-a-list-of-documents-in-site-collection

 

After finding my result from database, I thought to tried into SharePoint object model, here is link for finding page customization status from object model.

Easiest way to find file extension from SPFile Object

We can pass SPFile.Name object into FileInfo Class and get the extension of file. It will returns “.ASPX” or “.HTML” file extension depending upon file object.

 Example Code:   

SPFile objFile;

string strFileExtension = new FileInfo(objFile.Name).Extension;

Error occurred while starting of workflow (Could not load file or assembly Load Workflow Assembly System.IO.FileNotFoundException)

I was so frustrated to resolved above workflow error, because when I deployed my visual studio workflow solution package and started the workflow (manually or item created) then I was getting error in workflow status as “Failed on Start (retrying)”, also I didn’t see much useful information into workflow history, after looking into SharePoint log file, I have found below error.

Error:

Could not load file or assembly Load Workflow Assembly: System.IO.FileNotFoundException: Could not load file or assembly ‘ABC.dll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxx' or one of its dependencies.
I know that there was some problem into feature.xml or workflow.xml file into solution package, but after looking into details, I have found out that I made very silly mistake into workflow.xml file, there was one tag called “CodeBesideAssembly”, we need to write only assembly name like ABC into that tag, but I wrote ABC.dll into CodeBesideAssembly tag into workflow.xml file which caused the error while starting of workflow.

After removing extra DLL word from the file, my workflow was worked fine. So be careful while making workflow.xml file.

Keep Sharing…

Sunday, May 10, 2009

SharePoint Designer (SPD) Workflow deployment

One day I have very tough requirement, my requirement was to deploy my SharePoint designer workflow from development server to TEST server, I tried to find solutions from the internet but didn’t get any easy way for my requirements, at the last I have found one very good link which fulfill my requirements, though it requires some manual steps as describes in below link.

But now I can replicate same designer workflow to target server with some or more manual changes, I know that it’s very painful at some level to do manual steps, but we can say that it’s possible to deploy SPD workflow to other machine with manual effort ….

There is no direct way to copy designer workflow from one server to another server. Only thing which we can do is through “site template” also.

We need to save our SharePoint site as template in which we have created the workflow from SharePoint designer and using that template we can create a new site on another server which will have same workflow attached with it.

Here is link which describes manual steps to deploy designer workflow.

http://www.sharepointblogs.com/andynoon/archive/2007/09/18/reparenting-a-workflow-to-a-different-list.aspx

Enjoy working!!

Wednesday, May 6, 2009

Challenges while working with object model to access recurring meeting workspace site information

I was faced many challenges while getting all agenda list, document library from recurring meeting workspace site, because when we are accessing recurring meeting workspace into object model by SPList and other object, we are only getting data of first meeting instance ID, we are not able to loop through all instance at one place.

 

Many of the people were facing same problem like me, here is one of the link http://www.eggheadcafe.com/forumarchives/Sharepointwindowsservices/Aug2005/post23625925.asp

 

I did lots of search on internet and finally I found one line of code from which I got some direction to work on. I followed this link to find my solution, http://www.eggheadcafe.com/forumarchives/Sharepointwindowsservicesdevelopment/Sep2005/post23663884.asp

 

Points to be taken care:
1. There is one hidden list called “Meeting Series” into object model, which will store all the meeting Instance ID, so we need to take each meeting Instance ID from hidden list

 

2. We need to pass meeting Instance ID to SPQuery object, SPQuery contains property to hold Meeting Instance ID.

 

Sample Code to find out all data from recurring meeting workspace site:

 

        //Check if current Web is Meeting Workspace then execute below code

        if (SPMeeting.IsMeetingWorkspaceWeb(oWeb))

        {

            //Get Meeting Series list for taking Instance ID of each workspace site

            SPList meetingSeriesList = oWeb.Lists["Meeting Series"];

 

            for (int Cnt = 0; Cnt < meetingSeriesList.Items.Count; Cnt++)

            {

                int InstanceId = Convert.ToInt32(meetingSeriesList.Items[Cnt]["InstanceID"]);

 

                if (InstanceId != 0)

                {

                    // Use SPQuery to set Meeting Instance ID

                    SPQuery MeetingQry = new SPQuery();

                    MeetingQry.IncludeMandatoryColumns = true;

                    MeetingQry.MeetingInstanceId = InstanceId;

 

                    //Do Processing of SPQuery Object and get all Agenda List, Document Library data                  

                }

            }

         }

How to get Roles and permission for SharePoint site/web

There are two powerful classes into SharePoint Object model, one is SPRoleAssignmentCollection and second one is SPRoleAssignment, we can use this classes and find permission of any SharePoint objects, starting from Site, Web, Document Libraraies, etc..

Here I am writing sample code to find all the users permission into current web.

Sample Code:

  using (SPSite site = new SPSite("http://sitename/"))

            {

                using (SPWeb objMainWeb = site.OpenWeb())

                {

 

                       SPRoleAssignmentCollection oRoleAssignments = objMainWeb.RoleAssignments;

             foreach (SPRoleAssignment oRoleAssignment in oRoleAssignments)

            {

                             // SPRoleType provide enumaration for finding all user roles like  Administrators, Designer, Contributors, Visitors

                        //check oRoleAssignment.RoleDefinitionBindings.Contains(objMainWeb.RoleDefinitions.GetByType(SPRoleType.Administrator)) value
                   //  if current role is FULL CONTROL/Administrators then it will return TRUE

                SPPrincipal oPrincipal = oRoleAssignment.Member;

                  // oPrincipal object which will return SPuser or SPGroup, depending on current object

                             }

                     }

           }

        

Reference Link:

Finding roles and permission for list
http://dotnet.org.za/zlatan/archive/2007/12/23/getting-roles-and-permissions-on-a-list-document-library-level-in-sharepoint-2007-or-wss-3-0.aspx

 

Get RoleCollection for Web Site
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.roleassignments.aspx

 

What are the changes in authorization model into WSS 3.0(introduction of new class hierarchy)
http://msdn.microsoft.com/en-us/library/ms469194.aspx

 

How to get SPUser, SPGroup, SPRole objects
http://forums.asp.net/p/1012092/3068708.aspx

Tuesday, May 5, 2009

Limitation of SharePoint Designer(SPD) Workflow

SharePoint Designer is good tool to start initial or basic level workflow, I am not expert and good person to point out any limitation into any software, but as per me below are some of the limitation which I felt for SharePoint Designer Workflow, I’ll also write you more description about some of the limitation in coming posts …

  1. We don’t have facility to send BCC email to any person from “Send an Email” actions.

  2. We can’t bind and attach more then one list into designer workflow, though there are some manual steps from where we can fulfill our requirements, but there won’t be any easy steps from interface or GUI

  3. We can’t deploy/copy our designer workflow from one server to another server like there won’t be any easy way to deploy SPD workflow from development machine to TEST and Production Server; I’ll write how to do manual steps to achieve this functionality. here is my post regarding how to deploy designer workflow ...

  4. Designer Workflow don’t give us full customized editor from where we can customized our email body text, to do this, we need to write static HTML tags into email body part.

  5. We don’t write any calculation fields or formulas into Designer Workflow actions items, like I can’t extract only date from date-time column into designer workflow interface, for this I need to take one extra column into my SharePoint list and need to manipulate into designer workflow.

  6. While working in “Send an Email” action, if we add any list column from adding “Add Lookup to Body” button and if that column don’t have any values into SharePoint list, then it’s shows as ?????? instead of blank values into email body while sending emails …


I’ll update above lists as per my experience with designer workflow.

SharePoint Designer (SPD) Workflow

I am sharing some of my good repository links regarding working with SharePoint Designer Workflow.

 Good link to start with SPD Workflow – how to send email with list columns

http://rshelton.com/archive/2007/10/05/sharepoint-document-workflow-quothow-toquot---sending-an-email-with.aspx

 How to change task list for auto generated tasks for SPD Workflow

http://www.sharepointblogs.com/tbone/archive/2008/01/10/ode-to-joy-changing-the-task-list-for-auto-generated-tasks-within-sharepoint-designer.aspx

http://nickgrattan.wordpress.com/2008/04/29/changing-the-task-list-for-sharepoint-designer-workflows/

 Applying SPD Workflow to multiple lists

http://nickgrattan.wordpress.com/2007/10/17/applying-a-sharepoint-designer-workflow-to-multiple-lists/

 Best link which will describe how to “collect data from user” action activity

http://office.microsoft.com/en-us/sharepointdesigner/HA102098081033.aspx

 Good information for how to send email with customize email message, hyperlink into with SPD Workflow

http://office.microsoft.com/en-us/sharepointdesigner/HA102390421033.aspx

How to find GUID of SharePoint list

Till now I came across many articles related to finding GUID of SharePoint list from SharePoint interface/GUI, but I think, below is easiest way to find GUID of list.

Go to respective List – >Click on Settings Menu – > Click on List Settings Link- > here in this list settings page, we can find many links, we need to click on “Audience targeting settings” link.

Now, currently we are in Audience targeting page, look up at the URL of current audience target page, that the current address have GUID of list, at the end of URL we can find GUID, like ?List={552bef05-b62c-4c76-a217-35e85a1507f1}