Tag Info

Hot answers tagged

18

new SPFieldLookupValue(item["FieldName"] as String).LookupValue you probably want to check if item["FieldName"] is not null or empty before doing this. SPFieldUserValue works similarly, but you need to pass in an SPWeb into the constructor, which you can retrieve from your SPListItem using SPListItem.ParentList.ParentWeb


16

This is related how instance of SPListItem is being created. Actually in both cases new item is added to the collection of items in list, in first case new item is added explicitly, in the second one implicitly. The point is, that for initializing collection of items in list is used the same method GetItems but with different queries. ...


13

Instead of parsing them manually, try using the SPFieldLookupValue class instead: MSDN: SPFieldLookupValue or the SPFieldMultiChoiceValue class: MSDN: SPFieldMultiChoiceValue


12

You can use one of the SPUtility.ParseDate overloads. Check the article Converting Date and Time Values for more details.


11

A simple solution is to just validate the fields on submit by adding a validation rule in the list settings. Go to List Settings Open Validation settings under the General Settings area In the formula add your formula, I think it will be like this in your scenario: ...


11

You can also use SPQuery and a CAML query, like below. I also agree with what Dave Wise said about PortalSiteMapProvider class. SPQuery query = new SPQuery(); query.Query = "<Where><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">YourTitle</Value></Eq></Where>"; query.RowLimit = 1; query.ViewFields = ""; ...


9

If you use linq to object, you always retrieve ALL records from DB. It is not good if you have got a lot of data. To reduce records you can use CAML query: SPQuery query = new SPQuery(); query.Query = "<Where>" + "<Eq>" + "<FieldRef Name=\"FileLeafRef\"/>" + ...


8

What you are doing is something like this: ItemUpdating (attachItem.Update()) [internal]SPListItem.Update() Which causes the internal Update to fail because you have already done it. Try putting your code in ItemUpdated, rather than ItemUpdating. The flow is then ItemUpdating [internal]SPListItem.Update() ItemUpdated (attachItem.Update())


8

A better way of doing this is the SPFieldLookupValue class. MSDN has a good example. In short, something like: SPListItem lookedUpItem = GetItemSomeHow(); newItem[lookupField] = new SPFieldLookupValue( lookedUpItem.ID, lookedUpItem.Title); newItem.Update();


8

You load multiple items. A conflict occurs. Collect all items you need and call "load". After you call load for all items, then run context.executeQueryAsync. Save your selected items as a global variable (this.items): function showTitles(urlColumnName) { var context = new SP.ClientContext.get_current(); var web = context.get_web(); var lists = ...


7

If fetching of item["ID"] instead of 'Title' works AND If you are using the SPQuery object. Then, include the columns that you want to fetch in the ViewFields property of SPQuery. This will resolve your issue. Reference: ...


6

The main point here is that you can work with SharePoint Object Model from PS. So, your task is just to find out the way to change default field value using SharePoint Object Model, and translate it to PS notation. The default value for a column in SharePoint object model is set using SPField.DefaultValue property. So, let's try use this knowledge in PS. I ...


6

I anticipate that your root list has the same event receiver assigned to it, and that causes the recursion. The problem, of course, may be not so obvious, but anyway, to prevent event receiver to fire several times, there is a common practice in SharePoint: just use DisableEventFiring and EnableEventFiring methods. internal void ...


5

Use the ID of the lookup target: using(SPSite site = new SPSite("http://test.dev.com")) using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists["Suppliers"]; SPListItem item = list.AddItem(); item[SPBuiltInFieldId.Title] = "Test"; item["Product"] = 1; // Use the ID; get it from ...


5

You can use the SPWeb GetFile method to retrive the SPFile located at a specified url. Try something like this: SPFile file = SPContext.Current.Web.GetFile(string.Format("{0}/{1}", x, y));


4

I've had success by not using .ID, but using InternalName with .ContainsFieldWithStaticName(). I also check Hidden and CanBeDeleted on the field as these are more system fields and not custom ones, so I'm not worried about them. Sample below SPWeb web = SPContext.Current.Web; foreach (SPList list in web.Lists) { foreach (SPListItem item in list.Items) ...


4

Did you try the solution mentioned over on this post? Activating and deactivating publishing feature breaks SP2010 wikis? I don't know if it will work for you, but it might be worth a try. I didn't have any success with that previous answer though and went the other way and delved into the bowels of SharePoint and found that even though I was ...


4

Assuming that you already have a reference to the list item (called "item" in the following code sample), you must first get a reference to the list field and then use the GetFieldValue method to read the actual value. SPFieldUser userField= (SPFieldUser)item.ParentList.Fields.GetFieldByInternalName(internalName); var fieldValue = ...


4

2;#post1 is a SPFieldLookupValue where the LookupValue is "post 4" and the LookupId is 2. The LookupId of the item being looked up is the list item ID in the list it's being stored in. To set the value of a lookup field you have a few options: newItem["PostTitle"] = 2; // Just pass the lookup ID newItem["PostTitle"] = new SPFieldLookupValue("2;#post1"); ...


3

If you take closer look at versions.aspx (\14\TEMPLATE\LAYOUTS) you will notice that 'nice summary' is created by iterating over item versions (from line 311 to 357). My guess is if versions.aspx uses iteration to retrieve field changes then this is the only option available. Edited: To be completely correct: It is not the only option. You can probably ...


3

You could use the "Hidden" properties the query also returns, WebId, ListId and (Item)ID. These are returned by default for each result in an SPSiteDataQuery/ Then open the web using the WebId, then the List by it's ListId (convert both to GUIDs of course) and the item by ID. By sorting the result by webid, listid, id, you can speed up any iterations done ...


3

UPDATE When using SPListItem from a SPQuery, to access .File properties ensure you have fully loaded the item item = SPList.GetItemById(item.Id) ORIGINAL (Wrong) CheckOutType is an enumeration (value type) so can't be null. http://msdn.microsoft.com/en-us/library/s1ax56ch%28VS.80%29.aspx My guess is that item.File is null Try using: SPFile file = ...


3

Are there two fields for the list item that are people picker fields. I am assuming thats what you meant by stores which users are working on the project. If so you can modify the view by adding filters. Open the view and select modify. Go to the filter section and choose ProjectManager = [Me] or ProjectMember = [Me]. Is there any reason why you are not ...


3

Try this SPFieldUser assignedto = mySourceList.Fields["AssignedTo"] as SPFieldUser; ... ... foreach(SPListItem ...) { if(!UserDetails...) { SPFieldUserValue assignedUser = assignedto.GetFieldValue(mySourceListItem["AssignedTo"].ToString()); if(assignedUser != null) { string name = ...


3

The SocialRatingManager is the Master having up to date information about all ratings. The fields in the ListItem are just copies for easy access. If all you want to do is read/query/sort the rating of ListItem(s) which you have easy access to then you should use the Fields in the ListItem as this is the most convenient. The fields are updated by the ...


3

Answer to both of your question is - no, from msdn breaking role inheritance means - "role assignments on the parent object no longer apply to the child object, for example, so that role assignments on a list no longer apply to a list item." So permission granted on the document library (parent object in your case) never overrides the item level permission ...


3

SharePoint does not provide a method of restarting a workflow. You can however cancel a running workflow and start it again. A good example of canceling a running workflow can be found here: http://blog.brianfarnhill.com/2008/10/how-to-cancel-a-workflow-programmatically The snippit of code below will start your workflow. private static void ...


3

I found answer for my question. private string GetAttachmentUrls(SPListItem oItem) { string path = string.Empty; try { path = (from string file in oItem.Attachments orderby file select SPUrlUtility.CombineUrl(oItem.Attachments.UrlPrefix, ...


3

I got it working, with help from rjcup's answer (which help me link them together). here's my working (uncleaned) code: protected void btnStart_Click(object sender, EventArgs e) { string qmSPSiteURL = ConfigurationManager.AppSettings["qmSPSiteURL"]; using (SPSite site = new SPSite(qmSPSiteURL + ...


3

You can try following: foreach (SPListItem item in query) { SPListItem newItem = list.Items.Add(); foreach (SPField field in list.Fields) { if (!field.ReadOnlyField) newItem[field.Id] = item[field.Id]; } newItem.Update(); }



Only top voted, non community-wiki answers of a minimum length are eligible