Sharepoint 2010: How to persist SPList objects? - sharepoint

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?

Related

Sharepoint Concurrency Issue

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.

2013 reusable workflow current item values

My object is to create a 2013 reusable workflow that via rest updates a listitem in another list.
(This workflow will be copied via jsom and associated to newly created subsites, so it has to be reusable).
When I try to create variables from "Current item" the site column options are only standard. None of the custom site columns are available.
And there doesnt seem to be a way to use a specific content-type in SP2013 workflow.
Does anyone have a clue?
I ended up doing a differnet approach.
When a user creates a new project (subsite) the list item is created in the main "projectlist" and in the subsite "projectinfo" list.
I made a custom editform to use in the subsites. So when the user edites the item I save it via jsom to subsite projectinfo (where it is edited), then on the callback I update the corresponding listitem in the main project site.
Then i change window.location to the "target" from the query string.

Creating custom WebPartZone inside a webpart

i have one Webpart which shows an image slider. The image slider will be added by getting image url from webpart toolpart . and i will bind image slider in webpart using this.controls.add() method.
Here i need to allow users to add any webpart inside my webpart by creating a webpartzone. I think it is possible.
But the problem is everytime i'll create my control and webpartzone dynamically in creatchildcontrols() method. So if the user refresh the page the webparts inside the custom webpartzone 'll be deleted. Because i am building everying dynamically.
How to persist all the webparts and webpart proprties inside my custom WebPartZone, when the page refresh.
Please someone help me.
Why do you need to add zone? You can simply use ImportWebPart and directly add the control to your controls collection.
Regarding persisting the settings, the parent web part will have to do that for the children. For this to work, you can implement an interface on your child webpart, which the parent can call to get the settings. The settings can be serialized by parent webpart and stored in its personalization database.

Sharepoint 2010 WebPart: Users in Site Members Group can't save property of web part

I've created some custom property for my web part with Personalizable(PersonalizationScope.User) attribute. I changing this property in EditorPartClass in ApplyChanges() Method only. The main problem is user with contribute permission for a site can't save this property when editing personalized view of a page. Changing property applies when user click OK button on EditorPart, but after page postback value returns to its previous condition. Users with full control privilleges saves this property without a problem.
If User has an "Add and Customize Page" privilege property saves too.. But than User can modify web part in shared view too.. It's bad...
you need to explicitly change the SafeAgainstScript attribute on the SafeControl tags. This is new in 2010 because of the Client OM. you can't ever be sure that the user won't type malicious JS - so make sure you also encode any input your property takes!

Allow global configuration of a SharePoint web part

I have created a SharePoint web part which has custom properties that the user can configure. However these apply only to that instance of the web part. How could I provide the user a place to allow the user to set properties that would apply to every instance of the web part?
(I'm new to SharePoint development and am using WSPBuilder to create a web part with a feature and deploy it.)
You could use the Property bag of the SPSite's RootWeb (or, to make it SPWeb specific, the current SPWeb) to store global settings for that webpart (in that specific site collection). Create a LAYOUTS page to allowing editing of these settings if it's site collection wide, use RunWithElevatedPrivileges to store properties in an SPWeb's property bag.
Try a static member, eg:
[WebBrowsable(false), Personalizable(PersonalizationScope.Shared)]
public string configSetting
{
get { return _configSetting; }
set { _configSetting = value; }
}
private static string _configSetting;
It has been a bit since I used SharePoint... the first thing I would try is to create a List whose records are the parameters you want to feed to the webpart, and configure it so that the users can only see/modify their own record.
Caveats: this may be tricky if you want to make records dynamically appear whenever a new user registers. And also, lists are "local" to the site, so you can't have a single list which is seen from parts in different sites. (Or at least this is how it worked in SP 2007).
Depending on the number of parameters you need to properly configure the webpart you could also play around with custom "fields" in the user profile, but this is not very robust and would probably be an overkill.

Resources