Tag Info

Hot answers tagged

3

I could be very wrong but from what I understand, SPMetal only generates code which replicates the structure of a list in the form of strongly typed objects - the generated code has no relevance on the contents of a list. (Please inform if incorrect). To only retrieve published documents you need to read up on LINQ to SharePoint, to find out how to filter a ...


3

I got around this by extending the Item class in a new file because passing the <column name="" /> in the xml file and also trying <IncludeHiddenFields/> node did not work. This blog explains the process for extending the Item class. Here is an example of the code though you will need to add it to whatever namespace you are using for the rest of ...


3

As Waldek says in http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/df7b0a20-338c-41b4-bf35-d0cfefb39dc7 - only fields based SharePoint Foundation field types are used SPMetal. The publishing field types are Server specific. And the publishing fields are not intended for you to use directly, as you probably noticed they are not ...


2

I don't have enough rep to comment, so I'll have to add this as an answer... Try creating a new view for the list [in sharepoint designer]. Add the columns you want to this view, and set it as the default view. Then, regenerate the SPMetal classes. Incidentally, if you're using SPMetal with linq in a publishing site with anonymous access, be prepared for ...


2

I am thinking of giving ICustomMapping a go to create a ListItem property on my Entities of type SPListItem and use MapFrom() set it to be the item which it represents. I am just worried about object lifetime/disposal issues, i.e. I'm not sure if the ancestor path of the Item's SPList (SPWeb>SPSite) is still open after the Entity's properties have been ...


2

Short answer is "Unfortunately, yes, you have to generete .cs files again". After changing the list structure you need to regenerate cs files or create custom mapping. Piece of code from Joerg Krause "SharePoint 2010 as a Developer Platform" (by the way, it is a very nice book and I advice you to buy and read it if you haven't read it yet): public ...


1

To fix this issue I had to extend the classes generated by SPMetal. http://zimmergren.net/technical/extending-the-linq-to-sharepoint-context-to-allow-additional-fields-and-properties-in-your-queries is a pretty good resource for this except for the fact that I had to remove the namespace to get it to work (I'm not entirely sure why though. Can only assume ...


1

i think you can call it directly if im correct: List<SPListItem> items = (from l in list.Items.OfType<SPListItem>() where l["KPI Status"] != null && Convert.ToInt32(l["KPI Status"]) == 1 select l).ToList<SPListItem>(); hope this helps :)


1

It looks like there is not simpler solution that this one : public static SPPrincipal GetPrincipal(SPWeb web, int principalID, string principalName) { return web.AllUsers.Cast<SPPrincipal>().SingleOrDefault(u => u.ID == principalID) ?? web.SiteGroups.Cast<SPPrincipal>().SingleOrDefault(g => g.ID == principalID); } Feel free ...


1

I've done this by querying against the web.SiteGroups collection and the web.AllUsers collection, just as you have done, however I didn't cast. I instantiated an SPPrincipal to null and then set it equal to the SPGroup or SPUser before returning it. Here's an example using iteration rather than Linq: private SPPrincipal GetPrincipal(SPSite spsSite, ...


1

"PhoneBookConfigItem" is the default contenttype of your list? if not, your listinstanse xml missing the ContentType Field <Data> <Rows> <Row> <Field Name="ContentType">PhoneBookConfigItem</Field> <Field Name="Title">myItem</Field> <Field Name="Key">myItem</Field> <Field ...


1

spmetal will not generate the _ModerationStatus field because the field is not belong to the document contenttype. you can simply write a partial class to add a ModerationStatus property manually public partial class YOUR_DOCUMENT_CLASS { private System.Nullable<SPModerationStatus> _ModerationStatus; ...


1

The TaxonomyWebTaggingControl has a property Text. This will return the value in the format Label|Guid. To get the label, the code will be like this (from the top of my head) TaxonomyFieldValueCollection tagValues = new TaxonomyFieldValueCollection(); tagValues.PopulateFromLabelGuidPairs(TaxonomyWebTaggingControlName.Text); string ...


1

There are a couple of things i can tthink off: If you have the build target of the Web service project set to anything but "Any CPU" you will get Access denied errors, (I know, weird right?). Why not host the service directly under sharePoint. The WCF factories SharePoint provides make it dead easy to make the service available with fullblown SPContext ...


1

Get your Web var web = SPContext.Current.Web Create your file location var location = Path.Combine(entity.Path, entity.Name) call SPFile file = _web.GetFile(_location) Easier if you write it as a static extension method for the SPFile class.


1

There's the SPMetal Extender on CodePlex which might help, but I think you're gonna have to extend the entity further by adding a property to it which returns a Stream, and is effectively a proxy call to the object model. Of course, as soon as you need to run SPMetal again, you'll loose the custom property. Then again, you might be able to create an ...


1

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint.Linq; using Microsoft.SharePoint; public partial class MyClass: Page, ICustomMapping { const string SchedulingStartDateInternalName = "PublishingStartDate"; private System.Nullable<System.DateTime> _schedulingStartDate; ...



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