Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Programmatically changing the dates in a list

  Asked By: Aurelio    Date: Apr 05    Category: Sharepoint    Views: 3680

As i sent a previous post, hope the way i was approaching the
solution ain't right.
I have implemented an online bulletin board with sharepoint where
people can send their posts. After 30 days the post get expired and
will be still visible in there private list. All i want to do is to
write a webpart to change the ExpiryDate with adding 30 days which is
something like a Repost thing. All this is done with content
approval. So here is the code that i tried with, (only the main

private void createConn()
// Put user code to initialize the page here
this.Title = "Repost Webpart for bulletinboard";

int ID = int.Parse(Context.Request.Params["ID"]);

SPSite site = new SPSite("http://mainserver");
SPWeb web = site.AllWebs["sites/mysite"];
SPList list = web.Lists["bulletinboard"];
SPListItem listItem = list.GetItemById(ID);

ExpiryDate = DateTime.Parse(listItem["ExpiryDate"].ToString
CurrentDate = DateTime.Now;

if (DateTime.Compare(CurrentDate,ExpiryDate) <= 0 )
listItem["ExpiryDate"] = CurrentDate.AddMonths

catch(Exception mess)

This i am trying to achieve by sending the user to the webpart page
where the above webpart is. I am totally a new guy to C# and the
above im trying to build from a scratch. It seems the above code aint
working. Anybody have any idea? Let me know if there is a better way
to achieve this.



6 Answers Found

Answer #1    Answered By: Justine Barrera     Answered On: Apr 05

What kind of error message are you getting? There's several things that you sometimes need to do when doing updates. One of them is to set the AllowUnsafeUpdates to true before you do the update, then false after the update  is completed.

The other thing  you might need to do is impersonate the Sharepoing AppPool so you know it has enough security privleges to make the updates.

Answer #2    Answered By: Laura Walker     Answered On: Apr 05

I have given the error that im getting below.
pls guide me on this. Loadz of thanx.

System.Security.SecurityException: Request for the permission of type
System.Web.AspNetHostingPermission, System, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 failed. at
grantedSet, PermissionSet deniedSet, CodeAccessPermission demand,
PermissionToken permToken) at
permToken, CodeAccessPermission demand, StackCrawlMark& stackMark,
Int32 checkFrames, Int32 unrestrictedOverride) at
cap, StackCrawlMark& stackMark) at
System.Security.CodeAccessPermission.Demand() at
System.Web.HttpRequest.get_Params() at Repost.Repost.createConn()

Answer #3    Answered By: Cory Brooks     Answered On: Apr 05

What is the trust level at the bottom of the web.config file in your IIS
Web Site's home directory?

Answer #4    Answered By: Ruth George     Answered On: Apr 05

Trust level has been set to Minimal and impersonate yes. How does
this help us?

Answer #5    Answered By: Peter Peterson     Answered On: Apr 05

Finally i figured the problem. I guess Todd made me think, my credit
goes to him. Actually previously the Trust level was Minimal, after i
set the level for Full, the webpart  works fine (yuhooooooo!!!!).

Answer #6    Answered By: Kalyan Pujari     Answered On: Apr 05

Glad you got it working. The error message says that the assembly could
not present evidence for the permission being demanded. This is always a
Code Access Security trust level issues.

Didn't find what you were looking for? Find more on Programmatically changing the dates in a list Or get search suggestion and latest updates.