Sharepoint Concurrency Issue - sharepoint

I am totally new to Sharepoint development (Sharepoint 2013), and could use some help.
I inherited a console application where I'm getting this message below:
Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.
Actually, within the application and another console application (both running as jobs), there are numerous using blocks where they are newing up SPSite and SPWeb, opening the same list, and looping through the entries and posting update. These loop are incredibly slow. So the SPSite and SPWeb stays open for a long time, while additional SPSite/SPWeb are new'ed up to the same list.
Should I new up only one SPSite and SPWeb per application and use them globally within the application? Should I grab my list objects and assign them to a .NET List and close out the SPSite/SPWeb and then when I'm ready to update the record to temporarily new up a SPSite/SPWeb for the duration of the Update()? These list items are being updated by the other job as well while marching thru the list and posting updates to the same list. Is that an issue?
In reality, the notion of a Error Log list exists as well. Items are constantly being appended to this list. Would that cause that error message above?
Would create a Retry loop for the Update() work? Or is the issue of the list item updated by another process prevent a successful update?
Thanks.

Related

Workflow in Sharepoint Online

We have a document library hosted in Sharepoint Online with a single stage workflow attached that simply logs a few things and calls a web service. The workflow is triggered automatically when an item is updated.
The issue that we're having is that the documents are openned and changed in Word Online, which streams changes back to Sharepoint as they are made. This triggers the update event, but the document is still locked in Word Online so Sharepoint cannot even read the document metadata and the workflow hangs as a result. I need access to this metadata to pass to the web service.
The error is as follows:
Retrying last request. Next attempt scheduled in less than one minute. Details of last request: HTTP 423 to https://******.sharepoint.com/sites/etc/etc
The file "https://******.sharepoint.com/sites/test/Documents/test12311.docx" is locked for shared use by .
...and the action that it hangs on is:
Log The file [%Current Item:ID%] has bee... to the workflow history list
Once the browser tab is closed the lock is removed and the workflow completes.
Is what I'm trying to do even possible?

How can I persist web part state from inside a client web part content page?

I have just set up and created by first ever SharePoint development effort: a project for a web part, to be hosted in a SharePoint Online instance (my Office 365 trial).
I have figured out how to use the List API to pull the content I am supposed to present, being a rotating list of banner images, but I have one remaining concern. I would like to keep track of where in the list I am, and when last I changed images. Another question of mine answers this quite nicely if I go with local storage, but is there any SharePoint REST or JSOM API I can use to persist this state in the SharePoint service?
I like the local storage answer, but you could also write the state information to another SharePoint list.
Keep track of the information on a per user basis (probably against their user ID, since they'll likely be authenticated) and have send an AJAX request or a JSOM request without any visible callback behavior each time the viewer's state changes (maybe even use a web worker for users that support them).
Writing info to SharePoint lists isn't the fastest operation in the world, so it's possible you could have the banner rotate, the request fire, and the user close the browser before the request was complete -- but in that case they would just wind up on the same slide they were at before (so just repeating the last step in the rare occassion where this happens).

SharePoint Alternate Access Mapping error when indirectly using web services

SharePoint web site = http://myexample:3500
SharePoint tester (admin on domain, admin on SharePoint site collection) = IAmKyle
Alternate Access Mapping: I left it at the default which is http://myexample:3500 maps to itself, and the zone is "default".
My code was deployed as a farm solution and my .dll is in the GAC. I activated a feature on my site collection (url is above). What the code does is, when the user updates a SharePoint item, my code executes a LINQ query finding "related" items. Then the related items are updated. Here are the errors I get:
On Windows Event Logs:
Error loading and running event receiver [my receiver assembly]. Object reference not set to instance of an object.
On SharePoint ULS event logs:
Same error as I see in Windows Event logs. Also, I was getting errors about "alternate access mapping" not being configured for http://myexample:3500 but I'm not getting them anymore. Don't know why, I haven't changed anything.
On IIS logs
Getting some 401 responses for pages that I should be able to access. But, it only shows the tail end of the page in some cases e.g. "/mysite/mypage" so I'm unsure what the full URL is.
These errors are very confusing, my code 100% works on my test system. What network or sharepoint configurations should I be looking for? I'm assuming my code itself works fine considering that it does work on my test environment. Of course, I have more permissions on test since my username on test is the user who created the farm.
Thanks.
Do you get these errors when trying to activate the feature or when actually making a change to a list item?
Also, have you tried attaching the VS debugger to the process and having a look at what is going on?

Sharepoint 2010: How to persist SPList objects?

I am writing a replacement for the sharepoint asset picker dialog with additional features.
There is a requirement to browse media libs which are located in other site collections.
So I added a configuration page where you can add the URLs to the media libs to the sharepoint property bag.
In the custom AssetPicker dialog I added the SPList objects created from the configured URLs to a member List called medialibs.
I know that it is very important to dspose the SPWeb and SPSite the SPList object belongs to. I do that in the OnUnload event of the page, but discovered that OnUnload is calld every time on postback.
I can't rebuild the medialibs list every time in OnLoad because there is a treeview control on the page which holds references to the SPList objects in medialibs. If I dispose and rebuild them, the objects are new and different.
The treeview cannot be rebuilt every time, because it would lose the information which nodes are opened.
How do I persist the contents of the medialibs over postback? How do I ensure the SPList objects in medialibs are properly disposed when the user leaves the page?
Thanks!
I'm not sure why you would require medialibs to be persisted. On the initial load, you would populate the TreeView based on your SPList objects. ViewState then handles persistence of the TreeView across requests. SPSite/SPWeb objects would be disposed of at the population stage (using statements work well). Did I miss something?

Setting ModerationInformation.Status from Approved back to pending removes

Seeing if anyone else has had this problem and a resolution to it.
I have a visual studio sequential workflow on a list (not a library) which does NOT use tasks, the approval process is done through the Approve/Reject OOTB buttons on the list item. The approval is a 2 stage approval, whereby if the 1st stage is completed (via clicking the Approve OOTB button), i reset the ModerationInformation.Status from Approved back to pending then send an email to the 2nd stage approver.
My problem is, when i set the the ModerationInformation.Status back to Pending from Approved so there is never an approved version, the Creator loses permissions to view the item, and i get the "cannot find item" error from SharePoint for the person who created the item. The 1st and 2nd level approvers and anyone with approve rights CAN still see the item.
Some more background information. the code i am using to update the moderationinformation is
I get the properties from the workflow event and get a hook into the listitem
properties.Item.ModerationInformation.Status = SPModerationStatusType.Pending;
properties.Item.Update();
can anyone help.
Try using properties.Item.SystemUpdate(); this prevents SHarePoint from triggering any attached EventReceivers etc. I've had the same thing happen also. IMHO this is related to the fact that the item goes into update mode, then SharePoint basically has taken control over the item (seeing as workflows are usually run as the System account) but still sends you back to the the return url (i.e. the EditItem page of the list).
Since SharePoint is probably still doing work on the item (and when you use item.Update() it goes through all events etc. etc.) you cannot open it anymore, because you are not the system account.
When SharePoint finishes (after sent the emails etc.) the item is accessible by users again.
Like I said, I had the same thing happen during long running (i.e. longer than 2 to 3 seconds) EventReceivers / Workflows.

Resources