Pages

Saturday, January 9, 2010

How to use Sharepoint DateTime Functions in Annoucement Lists

Hi Friends

SharePoint has so many powerful attributes which is related with Lists like List views.

There are so many options provided by SharePoint Lists Views like Filter, Sorting, Groups and different layouts so that we do not need to code them all and we can specify as many as views we want.

I just passed through this powerful list view functionality. I need to display all announcements which are just one month old.

I used Date Time operation for that and that is where announcement expires date is greater than or equal to [Today]-30. You can see that in below image.














Enjoy Sharepoint!!!

16 comments:

  1. I've written a few articles giving tips on filters in SharePoint such as showing Tasks due in this Calendar month :-

    http://blog.pentalogic.net/category/sharepoint-ideas/

    ReplyDelete
  2. Hi Disha I have few questions about sharepoint workflow using VS2008

    I have a list " Company Expenses"
    it has the following list items
    Amount and Status
    now i want to write a worflow to automatically update Status to Yes when the Amount is 1000

    I have gotten so far can you help me complete this


    private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
    {
    String strAmount;

    strAmount = Convert.ToString(workflowProperties.Item["Amount"]);
    if (strAmount == "1000")
    {
    how to change list item status to yes where the amount is 1000

    }

    Thanks

    ReplyDelete
  3. Shashank

    If your requirement is that you just want to automatically update Status to "Yes" when the Amount is 1000 then you should go for "Event Handlers" not "Workflows".

    Write down "ItemUpdated" eventhandler on that list.

    If you want to know how to write eventhandlers please go through this block.
    http://dishashah.wordpress.com/2009/06/10/sharepoint-list-event-handler-types-and-example/

    If you have to use Workflow then you can do this
    private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
    {
    int strAmount;

    strAmount = Convert.ToInt32(workflowProperties.Item["Amount"]);
    if (strAmount == "1000")
    {
    how to change list item status to yes where the amount is 1000
    workflowProperties.Item["Status"] = "Yes";
    SPContext.Current.Web.AllowUnsafeUpdates = true;
    workflowProperties.Item.Update();

    OR

    SPItem myItem = workflowProperties.Item;

    myItem["Status"] = "Yes";


    SPContext.Current.Web.AllowUnsafeUpdates = true;

    myItem.Update();


    }




    Thanks & Regards
    Disha Shah

    ReplyDelete
  4. Thanks Disha

    I am experimenting with work flows and wanted to have a bare bones work flow with your help i was able to get it working thanks a lot

    ReplyDelete
  5. Shashank

    It is good to hear that you got success with your experiment. I am happy about this blogs helps you.

    Good Luck with Sharepoint.

    Thanks & Regards
    Disha Shah

    ReplyDelete
  6. Hi Disha

    Doubts about SPQuery . I searched a lot but could not find any article on SPQuery.
    here is what i know
    you can generate CAML using U2U editor or other editors but where do i put this caml query like eg

    *****************************************

    SPWeb web = SPControl.GetContextWeb(Context);
    string fullName = web.CurrentUser.Name;
    SPQuery oQuery = new SPQuery();
    oQuery.Query =
    "" +
    "'" + fullName + "'" +
    "" +
    "";

    so should code this in VS2008 or sharepoint .. that is what i do not understand about SPQuery
    if you could just post links or briefly explain that would be very helpful

    Thanks

    ReplyDelete
  7. Shashank

    Using Collaborative Application Markup Language (CAML) queries with SPQuery and SPSiteDataQuery is a faster and more efficient way of retrieving items based on known criteria compare with for each on the SPListItemsCollection and checking for the criteria.

    To answer your question, that SPQuery code should be inside Visual Studio. SPQuery is like filtering data from Lists. Please go through this msdn link. In that they also give example.So that you have clear picture of your SPQuery.

    http://msdn.microsoft.com/en-us/library/bb687949.aspx
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.aspx
    http://programmingsharepoint.blogspot.com/2008/03/searching-list-on-datetime-fieldspquery.html

    Hope this helps

    Thanks & Regards
    Disha Shah

    ReplyDelete
  8. HI Disha

    Previously i got so many solution from you, all are helpful to me.

    Thank you for all responces. I have one new problem

    I have a sharepoint site. which contains one document library. In the same time i have one asp.net application. My requirement is that, i need to open sharepoint document libraray document in asp.net site.

    But you shuold not copy that document in any asp.net server temprary location. I mean documetn should be open in live streaming.

    I hope you understood my problem.

    waiting for response

    Sai

    ReplyDelete
  9. Hi Sai

    Thanks for appreciation and I am always more than happy to assistant for the problems.
    There's 3 ways you can have your standalone ASP.NET (standalone meaning not integrated into sharepoint) interact with sharepoint.
    1>using the SharePoint object model (sharepoint APi dll's). This way allows you to control every part of how your ASP.NET site interacts with SharePoint (document security etc.) The major drawback is that you ASP.NET site needs to be running on the SAME SERVER as SharePoint (or if sharepoint is used in a farm any machine that is running sharepoint in that farm). Simply including the SharePoint DLL's will NOT work when run on any other machine (even when that machine also has sharepoint installed but is not part of the farm you want to communicate with!)

    2>Web Services. These OOTB Web services can be used from anywhere but are not very extensive functionality wise. They allow you to perform a lot of actions and retrieve a lot of data, but when it comes to more finegrained control they just don't cut it. It might be enough for what you want to do though.

    3>Use web services and create your own webservice that is deployed to sharepoint for any tasks not doable with the OOTB services. This requires access to the sharepoint machine in the form of deploying custom code / assemblies though.

    Hope this helps!!!

    Thanks & Regards
    Disha Shah

    ReplyDelete
  10. Hi Sai

    Thanks for appreciation and I am always more than happy to assistant for the problems.

    There's 3 ways you can have your standalone ASP.NET (standalone meaning not integrated into sharepoint) interact with sharepoint.

    1>using the SharePoint object model (sharepoint APi dll's). This way allows you to control every part of how your ASP.NET site interacts with SharePoint (document security etc.) The major drawback is that you ASP.NET site needs to be running on the SAME SERVER as SharePoint (or if sharepoint is used in a farm any machine that is running sharepoint in that farm). Simply including the SharePoint DLL's will NOT work when run on any other machine (even when that machine also has sharepoint installed but is not part of the farm you want to communicate with!)

    2> Web Services. These OOTB Web services can be used from anywhere but are not very extensive functionality wise. They allow you to perform a lot of actions and retrieve a lot of data, but when it comes to more finegrained control they just don't cut it. It might be enough for what you want to do though.

    3> Use web services and create your own webservice that is deployed to sharepoint for any tasks not doable with the OOTB services. This requires access to the sharepoint machine in the form of deploying custom code / assemblies though.

    Hope this helps!!!

    Thanks & Regards
    Disha Shah

    ReplyDelete
  11. Girdhari GaneriwalMay 21, 2010 at 2:02 AM

    Where do u work?

    girdhari@gmail.com

    ReplyDelete
  12. Hi,
    Pls help me out in is a member function in sharepoint 2007.
    (As i need to chec wether the user is a member of a particular group.)

    ReplyDelete
  13. Hi Tony

    You can write the following code to find out that user is related to which group.

    foreach (SPGroup singleGroup in SPContext.Current.Web.SiteGroups)
    {
    groupName = singleGroup.Name;
    inGroup = singleGroup.ContainsCurrentUser;
    if (inGroup == true)
    return groupName;
    }

    Hope This Helps!!!
    Disha Shah

    ReplyDelete
  14. Tony
    If you need to check just for a particular group, you can do this also

    SPGroup group = SPContext.Current.Web.SiteGroups["groupName"];
    inGroup = group .ContainsCurrentUser;
    if (inGroup == true)
    return groupName;

    Hope this helps
    Thanks & Reagrds
    Disha Shah

    ReplyDelete
  15. Hi Disha,
    I thank you for sharing your knowledge and experience with others and I find it is really helpful. I have been working with SharePoint 2007 for 5 months in business environment and I am kind of new to SharePoint.

    I have two questions and I believe you will be able to help me to find out a solution.

    Question 1

    I am using SharePoint approval workflow named “Approve Documents” which has a task list named “Workflow Tasks” and a history list named “Workflow History” to get approval for business documents. All the documents are stored in a document library for example”Invoice Approvals”. This document library has a drop down column called “Company Name”.

    My requirement is to display Company Name on Workflow Status page under any section (Workflow Information, Tasks, Workflow History) or anywhere on workflow status page.

    I appreciate if you could provide me a solution if it is possible.

    Thank you

    Question 2

    I create SharePoint sub sites under the parent site named “Project” using a custom template which has unique list level permissions(Each document library and list has unique permissions). But when I create a new site using this template all the permission settings are gone and it inherits permission from Parent site (Project).

    Is it possible to create sites using a site template which has same list level permissions as the template?

    Thank you.

    ReplyDelete
  16. Hi Anjani

    Thanks for appreciation.

    For your first question answer is this:

    Workflow Status is an application page. The link is http:///_layouts/wrkStat.aspx It is not recommended to modify the OOB(Out-Of-Box) page for SharePoint.

    Second, you can copy the page, and modify the new page. write the logic in the page.

    For second answer, please check the this msdn post,
    http://social.technet.microsoft.com/Forums/en/sharepointgeneral/thread/5794d350-272f-47c8-9f89-359eb138c62a

    If you have any question please let me know :)

    ReplyDelete