Hello Friends
Business Case:
In Project, Requirement is like develop one workflow steps like
1> Create task and Assigned To is its manager which is decided by Active Directory
2> Tasks are created like Originator à Project Manager à Director àDeputy à Superintendent. (Means we have to go to that level until whose manager does not exit.)
3> For every user we have to create one task .If it is approved or deferred we have to send mail. If it is approved we have to send mail to person who has created task for the manager and create a new task for next level.
4> Now if a person does not look at that task up to some duration we have to send email to person for overdue task and extend its due date for one day.
5> If person deferred task workflow must be terminated. And email also sends for task is deferred or cancelled.
6> Main requirement is that we have to search for manager from Active Directory.
Solution:
Develop a Sequential workflow.
Let us go into detail
1> Create new project Project Type Sharepointà Sequential Workflow.
2> Now Select activity that is “TaskCreated”.
3> Then we have to add one while activity where we put one condition check that manager name is empty or not and if not then workflow must be stopped.
4> Now there is one limitation of while activity is we add only one activity under while activity so I add one sequence activity and in that I add conditionactivitygroup there.
5> In that I add one activity which is “CreateTask” Activity .Then on I add “OntaskCreated” Activity.
6> Then I have to do like when task status changed from not started to Completed or Deferred we have to wait So I add one condition activity group which has condition like up to taskiscompleted == true.
7> In group of activities I took 2 Sequence Activity. First Sequence activity is as under

8> And another one is as follows.

9> In last once again we have to write one code activity which takes managername of current user.
10> Workflow is completed
11> How we can take manager name from Active Directory.
For that we have to use one directory Add reference
using System.DirectoryServices;
and also for regx you have to use
using System.Text.RegularExpressions;
private string getManagersName(string employeesName)
{
string managersName = string.Empty;
// Strip off the domain reference: eg: somecompany\\someusername. “somecompany\\” is the domain reference
string cleanUserName = employeesName.Substring(employeesName.LastIndexOf(‘\\’) + 1);
// Setting the Active Directory folder to the root foler
DirectoryEntry adFolderObject = new DirectoryEntry();
// Creating the AD Searcher Object
DirectorySearcher adSearcherObject = new DirectorySearcher(adFolderObject);
// Setting the Search Scope to the AD Root tree and the subtree
adSearcherObject.SearchScope = SearchScope.Subtree;
// Get the UserName of the person who uploaded the document from the Document Library
employeesName = workflowProperties.Item.GetFormattedValue(“Created By”);
cleanUserName = Regex.Replace(employeesName, @”<(.|\n)*?>”, string.Empty);
// Set the Active Directory Search Filter to the, now stripped, username
adSearcherObject.Filter = “(CN=” + cleanUserName + “)”;
// Execute the Active Directory Search
SearchResult adObject = adSearcherObject.FindOne();
// The Active Directory Search will return several properties for the Manager Object.
// Store them in an array
string[] properties;
// Ensure that the user has a value in the Manager field
if (adObject.Properties["Manager"].Count > 0)
{
// The properties are “,” delimited, so we will split the properties on that character
properties = adObject.Properties["Manager"][0].ToString().Split(‘,’);
// The Manager Name field starts with “CN=…”, so stripping that off leaves us with the
// Managers Name
managersName = properties[0].Substring(3);
// Get the Domain of the Users Active Directory Root
string domain = adFolderObject.Name.Substring(3);
// Convert the manager string to a SPU User Field
managersName = workflowProperties.Web.AllUsers[domain + "\\" + managersName].ToString();
}
// return the managers name or an empty string, if there is no manager
return managersName;
}
12> Second thing When you have list field type as “People Or Group” if you access fieldvalue and you want that thing display as “domainname\username”.You must have to use
employeesName = employeesName.Substring(employeesName.IndexOf(@”\”) + 1);
13> When you want to access some users which are in list and you want to use that name in task assigned list so you have to do one change and that is go to that edit that column and make Show Field as “Account”.
Now I will give you concept wise description.
ConditionedActivityGroup:
The ConditionedActivityGroup activity is a CompositeActivity, meaning the ConditionedActivityGroup activity is group of other activities. The ConditionedActivityGroup activity runs and re-executes child activities based on the evaluation of their when conditions. All rules are evaluated whenever required based on their data and state change dependencies. All of activities until an until condition is true of ConditionActivityGroup.
UntilCondition = this._IsTaskCompleted == True
SequenceActivity :
The SequenceActivity is a CompositeActivity, meaning the SequenceActivity can contain other activities.
The SequenceActivity class coordinates a set of child activities in an ordered manner, one at a time. The SequenceActivity is completed when the final child activity is finished .There is one when condition is attached with Sequence Activity. If we do not specify that condition then it executes all activities under Sequence activity one at time but if we wish to executes all activities must run under some condition we can specify that thing under when condition and when it is true then and only then all activities run.
First Sequence Activity When Condition : None
Second Sequence Activity When Condition : this._IsTaskCreated == True && this._IsTaskCompleted != True
DelayActivity:
The Delay activity causes the containing branch of the workflow to wait for a specified amount of time
I need that otherwise workflow goes into infinite loop I have to tell workflow to wait for 2 minutes. Then check code condition for due date.
Hi Disha
I am new to Sharepoint. I have couple questions in document library and Ajax with sharepoint.
1) Document Library
I am uploding the documents in sharepoint document library using custom webpart(Bulid in C#). But the documents are stored in document library with status “Draft” . That should be stored in the doc library with approve status. So for this what change i have to do in my coding. Already i tried with checkin/checkout. I am using below code for uploading
using (SPSite siteCollection = new SPSite(siteUrl))
{
using (SPWeb spWeb = siteCollection.OpenWeb())
{
SPDocumentLibrary doclib = (SPDocumentLibrary)spWeb.Lists[ConfigurationManager.AppSettings.Get("DocLib").ToString()];
SPFolder root = doclib.RootFolder;
Byte[] fileContent = null;
fileStream = File.OpenRead(FilePath);
fileContent = new byte[Convert.ToInt32(fileStream.Length)];
fileStream.Read(fileContent, 0, Convert.ToInt32(fileStream.Length));
spWeb.AllowUnsafeUpdates = true;
root.Files.Add(strSelectedFolder + “/” + FileName, fileContent, true);
}}
2) Ajax
If i will use custom coding for implementation of ajax in sharepoint, then it works in custom master pages and custom pagelayout screens. But its not worked in userpages (I mean default.master,bluband.master)
Thanks in advance
Comment by Sai — July 31, 2009 @ 3:31 pm |
Hi
Thanks for Comment.
Now, Answer related to your first question.
1. I think you need to change your document library settings from the GUI and when you upload your documents through code, it will store in Approve stage.
Can you please try below things from SharePoint site and try to upload documents from code?
1.1 Go to your document library list
1.2 click on settings->document library settings
1.3 click on version settings under settings section
1.4 First section which says require content approval for submitted items, check “NO” and click on SAVE
1.5 now uploads your documents
If this won’t work then I’ll see from coding point of view,
2. for Second Question
If you open any master page which is related to publishing Portal Template you find this tag
You NEED to make CHANGES for Enabling AJAX with this
NOTE: Master pages structure is different which are related to Publish Portals and Other Site Templates (Like TeamSite, blankSite) Etc…
Thanks and Enjoy
Disha Shah
Comment by dishashah08 — July 31, 2009 @ 4:07 pm |
Hi Disha
Thanks for your feedback. Now i am able to upload the document and it is visible to all the authenticated users. But we are facing one more issue, the old documents which are in draft status are viewing to only to that user who is uploaded that one. Are we able to make public those documents?
Regarding AJAX.still now i am not clear. Can you provide any small test application, for the same. I have to create custom webpart and it should implement AJAX. i have to add that webparts in system defiend pages. Piease of code whih is i used for “checking script manager” is as follows. But it throws the error.
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
try
{
EnsureScriptManager();
EnsureUpdatePanelFixups();
}
catch (Exception Ex)
{
this.Controls.Add(new LiteralControl(Ex.Message));
}
}
private void EnsureScriptManager()
{
ScriptManager ajaxScriptManager = ScriptManager.GetCurrent(this.Page);
if (ajaxScriptManager == null)
{
ajaxScriptManager = new ScriptManager();
ajaxScriptManager.EnablePartialRendering = true;
if (this.Page.Form != null)
{
this.Page.Form.Controls.AddAt(0, ajaxScriptManager);
}
}
}
private void EnsureUpdatePanelFixups()
{
if (this.Page.Form != null)
{
string formOnSubmiAtt = this.Page.Form.Attributes["onsubmit"];
if (formOnSubmiAtt == “return _spFormOnSubmitWrapper();”)
{
this.Page.Form.Attributes["onsubmit"] = “_spFormOnSubmitWrapper();”;
}
}
ScriptManager.RegisterStartupScript(this, this.GetType(), “UpdatePanelFixup”, “_spOrginalFormAction = documnet.forms[0].action”, true);
}
Comment by Sai — August 3, 2009 @ 2:18 pm
Hi Sai,
You need to publish your all old documents from draft to publish status, so then all users can see those documents, if you are using “Publishing” site templates, then there is some way from which you can get reports of all draft documents and you can publish them all by clicking only one button. But again, these all are manual steps to make old documents available to all users.
Can you please give me some more detail description for what exactly are you looking for AJAX implementation into SharePoint?
Thanks,
Disha Shah
Comment by dishashah08 — August 3, 2009 @ 2:47 pm
Hi Disha
Thank you. Even i able to implement Ajax. Now i am facing another problem. I have a site in sharepoint, which has one document library is there. I need to access those documents in asp.net site. While i request fro document from asp.net site (e.g. Like this http://servername:port#/documents/test.pdf), it asks credentials. I want that document should open directly(With out credentials). Is there any way to archive this.
Advance thanks.
Sai
Comment by Sai — August 8, 2009 @ 10:52 am
Hi Disha,
How can i insert a Bulk data into Sharepoint List..using coding.
Thanks in Advance.
Regards,
Nitin
Comment by Nitin — August 10, 2009 @ 10:08 am |
Hey Nitin,
There are many ways to insert bulk data into SharePoint list using coding, it’s depend on case to case basis, like what will be source of bulk data, it’s from database or any other flat file, etc …
In general scenario – You can take data into datatable or recordset and loop through your records and insert into SharePoint list by ListItem class/methods.
Can you please give some more idea about your requirements?
Thanks & Reagrds
Disha Shah
Comment by dishashah08 — August 10, 2009 @ 1:59 pm |
Nitin,
You can also do one thing, you can write web service call to your SharePoint list and use LISTS web service to update/insert bulk data, you need to generate your XML nodes with all your required SharePoint list columns and values and then pass same values to LISTS web service/methods.
Thanks,
Disha Shah
Comment by dishashah08 — August 10, 2009 @ 2:41 pm
Thanks Disha.
I have implemented the Bulk insertion in Sharepoint List by creating XML with “Batch” node and passing that XML to ProcessBatchData method.
Thnaks a lot.
Regards,
Nitin
Comment by Nitin — August 11, 2009 @ 4:53 am
HI Disha,
ther is a requirement from Client like, From drop down he can select a cityname once he selects the city from list and click on submit, data has to be save with cityname and his details. After that once this request is done mail has to go to the requested person as well as Administrator….
So i am planing to insert this data into Task list and assign the workflow to send the email….but i am not getting succeed while doing cutoms workflow using Visual studio. If this approach is correct could you pls tell me how can i go ahead with this.
Thanks in Advance.
Comment by Nitin — September 10, 2009 @ 2:13 pm |
Hey Nitin,
Please let me know, do the client need any kind of approval or rejection into your list?
If not then you can go with Event handler approach without creating workflow like when you add Item, on ItemAdded event, write a code for sending email to people and provide some link to Administrator in email so he can response back to that from email..
Yeah, you can do same thing with SharePoint Designer workflow as well as also Custom Visual Studio Workflow. It’s all depending on what are exact requirements for workflow.
Can you please tell me what your exact problem is? You are not able to add task in task list or not able to send email or problem with deployment of workflow or when it started it gives error like “failed to start” or some another error (clarify me on this so I can help you out)?
FYI: For sending email you need to configure farm settings for outgoing email with your smtp server, when you deal with workflow please be careful with correlation token.
Thanks,
Disha Shah
Comment by dishashah08 — September 10, 2009 @ 3:32 pm |
Disha,
Can we add buttons in list like in grid we can have button int each row?
Is it possible in list to add buttons in each row?
Thanks in adavance
Regards,
Nitin
Comment by Nitin — September 11, 2009 @ 9:06 am |
Nitin,
Can you please let me know which list are you talking about? Is it Custom list or any type of custom or out of the box web part?
One thing you can do, you can use SP Grid View control into your custom code instead of normal ASP.NET grid control and you can include all functionality of normal SharePoint list menu into SP Grid View control, it’s same like if you see display form of any SharePoint list.You can use SPMenuItemTemplate for that.
Once you will use SP Grid View control then you can also add buttons into each row …
Thanks & Regards
Disha Shah
Comment by dishashah08 — September 12, 2009 @ 3:28 am |
Disha,
I have doubt while implementing permissions for each users
Below is the requirments.
1)THere will be two users, admin and End users(will be Many)
2)End user will make a request for particular document. Once he make request data will insert in to one MasterList say “DocumentList”
3)In this list i am storing the info users with his Email id, login id, and Document Name
4)Admin will approve this request, for this iam just creating custom webpart.
After that End user will login for whom admin has approved.
Once he loggedin he should see the entry in his list.
But second end user should not see his entry because he has not make any request for this.
5)Finally it means that Each users should see there approval document in there list.
Now my requirement is that
i wanted to display the master list data depends on the logged in Users.
I wanted to select data based on the users login.
How can i do that? Please suggest how can i achieve this.
Comment by Nitin — September 21, 2009 @ 11:51 am |
Hi Nitin,
If I understood your requirements correctly, then you want to display data from some list called “master list” depends on logged in users , I mean if userA created two records out of five records into custom list, then you want to display two records when userA login into SharePoint site.
For achieving above requirements, you can create custom view into SharePoint list and mark created custom view as “Default” view for all users, now into custom view you can put filter criteria by specifying username as [Me]. That mean it will display all the records created by logged in users.
Hope it will help to you.
Thanks,
Disha Shah!!
Comment by dishashah08 — September 22, 2009 @ 2:25 am |
Thanks Disha..
It helps for me.
Comment by Nitin — September 22, 2009 @ 5:20 am
Hi Disha
Can i fill a custom list from external data base. But that list alwasy connected with that external db table. If any change will occur in external table, than automatically list should update. How will i acive this.
One more question, i created one custom field in sharepoint. Its working fine. But in column defination it should display to owners group. is it possible. Column defination means, while you click create column it shows types of coulm like (Single line text, Multiple Line text, also my custom fields). On that screen it should disply to only owners group.
Thanks in advance.
Sai
Comment by Sai — September 24, 2009 @ 7:03 am |
Hi Sai
Yes you can fill custom list from any external database with writing code to access DB directly or with BDC code you can achieve this …
But I think you have to write code to update your list automatically which will synch with your external database. It’s depend on which external database you are trying to connect, you can also write SharePoint timer job which will go into your external database on specified time and update your SharePoint list with your updated records, there are different type of solution to achieve functionality.
For your second question regarding displaying custom field to owners group, I am not following you correctly, do you mean that your custom field which is displaying on create new column page – will display or visible to people who are in owner group? Please correct me if I am misunderstanding.
I am not sure that whether you can do that or not, I am thinking that you can check current user into your custom field and display/visible your data type based on owner group. Even if that’s just my idea…..
Thanks,
Disha Shah
Comment by dishashah08 — September 26, 2009 @ 11:00 pm |
Hi Disha
Thanks For your reply.
I succeed in my first question. Regarding second question you are correct, i require this funnctionality in create column page. coulmn defination, which is devloped by me should display to owner group only. That is the requirement.
One more question
, I never developed any workflow in VS 2008. I devloped in sharepoint designer, but with sharepoint designer features, my requirement is not full fiiled. Becoz through designer we can’t achive looping. I have a requirement now. There is issue trcker list is there. ASA admin will post one issue than “asigned to” fellow should get one mail that one issue is assigned to you. Than assigned fellow should approve or reject the issue. If he approve the issue, that he should confirm – Due date is ok or not. At last assigend fellow update the taske with complet staus. If assigned fellow reject the issue, than admin should reassign to any body. Than once again steps will go. At last work flow should complete.
Thanks in advance
Sai
Comment by Sai — September 28, 2009 @ 6:43 am
Sai,
That’s great you got success in your first question.
Regarding second question, as I have explained you that please try to see whether you can write custom code to check current user into column definition or not..
I understand your requirements regarding workflow, I am not sure what exactly you are looking from me, but you can take reference from below link for visual studio workflows.
GOOD WORKFLOW LINKS:
http://sheltonblog.com/archive/2007/11/21/how-to-video-building-a-basic-approval-workflow-with-sharepoint.aspx
http://rshelton.com/Tags/Workflow/default.aspx
Thanks!
Disha Shah
Comment by dishashah08 — September 28, 2009 @ 3:11 pm
Hi,
Dishashah I’m new SharePoint, I want display display records in Grid When the page load in SharePoint. Which event I use, Please..
Thanks
Govindaraj
Comment by Govindaraj k — September 30, 2009 @ 6:30 am |
Hi GovindaRaj,
If you are displaying records in grid into custom ASPX page then you can write your code into page load event, and you can also write your grid code into different events as per your requirements like you can also trigger your code on button click on something else .
Please let me know if you are thinking to achieve something else with grid!!
Thanks,
Disha Shah
Comment by dishashah08 — October 1, 2009 @ 5:26 pm |
Hi Disha,
I want some sample coding about AspMenu for sharepoint
ex.
File
New
open
K. Govindaraj
Comment by Govindaraj K — October 4, 2009 @ 9:54 am |
Hi Govindaraj,
You can use SharePoint:AspMenu and to display menu items, you can use “asp : SiteMapDataSource”. Try to search on both these things and fulfill your requirement.
Thanks!
Disha Shah
Comment by dishashah08 — October 6, 2009 @ 1:57 am |
Hi, Disha
I Create one button in Sharepoint Designer, I want to write the coding for button in Sharepoint Designer, when I click the button it will display some text, how to write code. Please
Govindaraj. K
Comment by Govindaraj K — October 5, 2009 @ 6:09 am |
Hi Govindaraj,
It depends on your requirement of your button click, if you just want to do validations you can use JavaScript as you write in any HTML or ASPX page, and if you have any long and complex Requirement, I will prefer go with Web part.
Sample code for writing PAGE LOAD event into SharePoint Designer:
protected override void OnLoad(EventArgs e)
{
Response.Write(“This is from the onload event”);
base.OnLoad(e);
}
Thanks and Regards
Disha Shah
Comment by dishashah08 — October 6, 2009 @ 2:02 am |
Thank you, Disha Shah
Govindaraj K
Comment by Govindaraj K — October 6, 2009 @ 3:38 am |
Hi, Disha
I Designed one form in SharePoint Designer, textbox and buttons.
When I type text in the textbox, and it want to store in the SQL Database.
can you help me to do this. Only in SharePoint Designer.
Govindaraj K
Comment by Govindaraj K — October 6, 2009 @ 4:55 am |
Hey Govindaraj,
I don’t know for which reason you want to do programming with SharePoint Designer, I think it’s not possible or little bit difficult to write complex programming into SharePoint Designer Pages. If you find any way to do so then please share with me, thanks!
But in my opinion you can do this thing – create one ASPX page and write your saving of data code into ASPX page, put same page into _layouts folder, so in this way, you can open your ASPX page from SharePoint site.
OR
You can also create one web part and put your logic which will save data into SQL Server inside web part.
~Disha Shah
Comment by dishashah08 — October 8, 2009 @ 1:24 am |
Hi Disha,
I have created a Task edit form in ASP.NET, But when i try to access this form with following url
“http://servername/CustomApprovalForm/DesginApprovalForm.aspx” i am getting following error
“The virtual path ‘/_catalogs/masterpage/default.master’ maps to another application, which is not allowed ”
I have tried with creating ASP.NET application using HTTP as well as FileSystem. But still i am facing same problem.
Even i have changed the settings in IIS under _layouts folder by setting application name to Root…But still same error
Could you please suggest any solution to resolve this issue?
Thanks in advance
Regards,
Nitin
Comment by Nitin — October 7, 2009 @ 12:34 pm |
Hi Nitin,
Can you please let me know that where you put your ASP.NET created ASPX page, I mean which directory or how you deploy your page?
If you want to see your ASP.NET created ASPX page into SharePoint site, then you have to put that ASPX page into 12 hive/layouts folder directory then you can access your page from http://yoursharepointsiteurl/_layouts/aspnetaspxpage
I think its nothing to relate with IIS settings or how you created your ASP.NET page, the things here is how you deploy your ASPX page into SharePoint site.
I hope that from above information you can get some direction to work on!!
Disha Shah
Comment by dishashah08 — October 8, 2009 @ 6:27 pm |
Hey Sai,
You can try to write with two options.
1> Your code between spsecurity.runwithelevatedprivileges delegates.
2> try to pass current credentials by using this class “System.Net.CredentialCache.DefaultCredentials” to the SharePoint site/document library.
Ideally speaking, the user who is trying to open documents from ASP.NET site needs to have correct access privileges into SharePoint site also. So I prefer to use “System.Net.CredentialCache.DefaultCredentials” option.
Thanks,
Disha Shah
Comment by dishashah08 — August 10, 2009 @ 2:56 pm |
Hi Disha
Thanks its worked.
One more question
In my sharepoint site already one content type is there. That content type consists one column(dropdown). My requiremnt is, i have to fill that column with items which will come from external data base(e.g. Oracle). So how can i achive this. Please help. Thanks in advance.
Comment by Sai — August 13, 2009 @ 1:41 pm |
Exact requriement is,
1)External user will make a request For perticular city
2)After request, mail need to send to Administrator stating that there is a request from external user as well as mail need to send to Requested person(External user).
3)Administrator can Approve the request or Reject the request.
once approve the request mail need to snd to external user and data need to insert in a list.
Thanks in advance
Regards,
Nitin
Comment by Nitin — September 11, 2009 @ 4:41 am |
Hi Sai,
It’s good to hear that it’s worked!!!
Now regarding your question – I have general idea about how to achieve that …
I think there are different different ways for meeting those requirements.
1.
1.1. Write ADO.NET code to connect your external database (oracle) and make a record set (data table or any other) which returns the values which you are looking to fill into drop down of content type.
1.2 There are many classes into SharePoint object model which gives facility to play with Content Types, Class Name called “SPContentType” and you can also get specific content type from LIST by doing “LIST.Content types” ….. Try to take the content type into your code and assign values from your data table which you already filled from oracle database.
2. You can also create BDC data connection which has connection to your external database entity, and into your code you need to take your SharePoint site SSP and BDC entity which you created for oracle database to get the data from oracle – here we are trying to achieve step # 1.1 – for filling data.
Then you can go with step # 1.2 to assign values to content type.
You need to look for exact class name and syntax for content type…
I hope above answer give you some idea to start with your work.
Good Luck!!
Disha Shah
Comment by dishashah08 — August 13, 2009 @ 2:19 pm |
Hi Sai,
Can you please provide the code for opening documents from asp.net site? I am struggling to get this working without getting asked for credentials. My application search a document library in Sharepoint and lists the document in a grid. When the user clicks the document they get asked for credentials. The url to the document is something like http://servername/documents/test.pdf
Comment by Oyvind — September 21, 2009 @ 5:10 pm |
Nitin,
By Looking at your requirements, I think SharePoint designer workflow is easiest, In designer workflow you need to add each steps and take respective activity like “Send Email to User” for sending email to administrators and users, then for approving or rejecting items, you can take “collect data from user” activity and so on …..
Deployment in SharePoint designer workflow is not easy, here are limitations for designer workflow http://sanketinfo.wordpress.com/2009/05/05/limitation-of-sharepoint-designerspd-workflow/,
and you can also create same workflow in visual studio and use feature to move visual studio workflow from one environment to another environment.
Thanks & Regards
Disha Shah
Comment by dishashah08 — September 12, 2009 @ 3:41 am |