Page Checkout with System\Sharepoint everytime.

Jan 20, 2010 at 5:38 AM

Hello Again,

I have become a big fan of CS.NET

There is the strange error occuring that, user with permissions can create and publish the new page using CS.NET but after that if same user tries to edit the page it says page is already checked out by another user i.e. system\sharepoint.

In short, 

correspondingListItem.File.CheckOut() checks out file with user with which application pool is created.

This issue has been faced by number of other users also, posting some links:

http://stackoverflow.com/questions/1460222/check-in-and-check-out-in-spfile-object

http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/2cf226bf-1fce-4866-87ef-f00c696ecbcd

I have debugged code extensively but not really sure what change is needed. Some help would be really appreciated. I am using CS.NET 2.0.

Thanks in Advance.

Coordinator
Jan 20, 2010 at 5:41 AM

Hi,

The easiest way is not to login at all using account that corresponds to System Account (ie. account used to install Sharepoint).

Cheers,
Tommy

Jan 20, 2010 at 5:51 AM

Well, thanks for fast reply.

You are saying once the sharepoint is installed then one should never login to the site with that user name. That will be very difficult.The user who creates the site collection is used as theprimrary administratorof the site. That will make that user who corresponds to the System Account.

Can you suggest code change for this? Are you aware of this issue?

COde where change might be needed is as follos with bit of modification:

<font size="2" color="#0000ff"><font size="2" color="#0000ff">

public

</font></font><font size="2" color="#0000ff">

 

</font>

void Checkout(CompleteSharepoint.Repositories.PublishingPageEntity publishingPage)// Only checkout if status is not checked-out to someone and not draft (ie. hasn't ever been published). 

{

           if (publishingPage.PageStatus.PageCurrentStatus != CompleteSharepoint.ContentManagement.Repositories.PageCurrentStatus.Checkout)

           {  publishingPage.CorrespondingListItem.File.CheckOut(); }<font size="2">

}

</font>

 

 

Coordinator
Jan 20, 2010 at 5:59 AM

Hi,

The best practice is to always have different username for running each Sharepoint service including the user that installs Sharepoint.

For example:
- SP_Admin for installing SP
- SP_Farm for running SP Service
- SP_Search for running search, etc
- Then your user account as the Full Control / Site Collection Administrator account on a site that you created

This will fix the problem I think.

The thing with modifying the code is, that Checkout code is using Sharepoint object model. We'll never know how it does it. That CorrespondingListItem is really just retrieving the SPListItem object of that publishing page. If you open UserController, you'll be able to see that I put some IF ELSE statement just for this very reason. I totally understand where you came from with that error because I also get that error originally when developing CS.NET.

Cheers,
Tommy

Jan 20, 2010 at 6:08 AM

THANKS A LOT.

I will follow the same process. Though if I find any solution for this I shall inform you.

Thanks a ton again.

 

Jan 29, 2010 at 10:54 AM

Hello Again,

Probably the issue is in following code. If I try to checkout the page from OOB page then it checks it out with Current Users permissions but if I try to check it out with CS.NET "Edit Page" option then it checks it out with System Account user. That means issue is in code.

Now, the first block of code that runs from CS.NET code with elevated privileges is following

File Name: BaseWebPArtPage.cs

protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                WebPartManager wp = WebPartManager.GetCurrentWebPartManager(Page);
            if (wp.DisplayMode.Name == "Design" || wp.DisplayMode.Name == "Edit")
            {
                this.SetFormModeToEdit();

                if(wp.DisplayMode.Name == "Design")
                    this.CheckoutCurrentPage();
            }
            });

        }

 

If I make it like this:

protected override void OnLoad(EventArgs e)
        {

try

{
            base.OnLoad(e);

            WebPartManager wp = WebPartManager.GetCurrentWebPartManager(Page);
            if (wp.DisplayMode.Name == "Design" || wp.DisplayMode.Name == "Edit")
            {
                this.SetFormModeToEdit();

                if(wp.DisplayMode.Name == "Design")
                    this.CheckoutCurrentPage();
            }

}

catch{}
}

and use it it works perfectly fine.

Let me know if this solution is correct. and would it through an exception and if it does then what will be the probable suggestion from you.

Thanks!

Coordinator
Jan 29, 2010 at 4:37 PM

If that works than that's great.

The only thing I would test is using Anonymous Account. I think from memory if you remove the RunWithElevatedPrivileges, anonymous users will get prompted.

Can you please test this? If they don't get any credentials prompt and I'm more than happy to accept your solution and I'll post an upgraded version asap.

 

Thanks so much for your participation thus far,
Tommy

Feb 1, 2010 at 4:24 AM

Thanks Tommy,

I am using CS.NET for intranet application where there will not be the anonymous users. But I shall still test this one for you once I get time.

Also, Since this block of the code runs only on doing "Edit Page", particular user is always going to have the privilieges to access the WebPartManager for the page, so no need to elevate privileges.

Correct me if I am wrong / missing anything.

Thanks!