0

Where can I find the raw definition within the Content database of a View on one of my Lists. I've found the list in AllLists and the View, I think, in AllDocs. But from there the trail is cold. I can't find the next table with a matching DocID or whatever with data.

It's not in tp_Fields or tp_ContentTypes.

I just want to look. I assume it's encoded as CAML (possibly compressed).

Thanks!

  • Why do you need to get it from the database? You can use both managed and JavaScript code to retrieve the CAML view definition – MdMazzotti Apr 6 '14 at 6:36
  • Well, I guess I'd rather not have to write either if I can just look it up. But I didn't know you can do that. – Jason Kleban Apr 6 '14 at 17:54
3

Writing queries directly on SharePoint databases is highly discouraged. You should consider the database as a black box which you can interact with through the provided APIs (either SSOM, CSOM, REST or web services).

Here's how you can retrieve a view definition, using

SSOM:

SPView oView = oWebsite.GetViewFromUrl("Lists/List_Name/View_Name.aspx");
var schemaDefinition = oView.HtmlSchemaXml;

SSOM /w PowerShell

$web = Get-SPWeb "http://localhost/site"; 
$view = $w.GetViewFromUrl("Lists/MyList/MyView.aspx"); 
$view.HtmlSchemaXml

CSOM:

var ctx = SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle(listName);
var view = ist.get_views().getByTitle(viewTitle);
ctx.load(view);
ctx.executeQueryAsync(function(){  
   var schema = view.get_htmlSchemaXml();
}, function(){ //on error })

WEB SERVICE:

here's the reference on the Views webservice

//code omitted for brevity
viewService.GetView("List_Name","View_GUID");
  • +1 I appreciate these code samples, but I have to say that the apparent refusal to answer the real question in an effort to protect me from myself is ... obnoxious. There's no harm in looking manually at the data. If I were accessing it this way programmatically, I agree that would be a poor choice. But even then, just provide a warning but still answer the question (if known). These code samples require quite a bit of scaffolding just to get the CAML of the view to extract its filters, etc, and one shouldn't have to justify the question with a detailed description of the scenario. – Jason Kleban Apr 7 '14 at 13:35
  • Not just directed at you. In reviewing other questions, I found other such prefaces: "it will put your environment in an unsupported state and we (in this community) cannot provide you any guidance that would result in such". vs A much better answer – Jason Kleban Apr 7 '14 at 13:39
  • 1
    @uosɐſ I slightly rephrased my answer to soften the peremptory tone (which I too oftentimes find hateful). But don't expect to get many answers here if your question is about directly querying the DB. As a final note, I wouldn't really call "quite a bit of scaffolding" the code required when using the SSOM. It's just a line of code (+ one not shown for getting hold of the SPWeb object). You can even use it in PowerShell. A T-SQL query wouldn't certainly be shorter than this. – MdMazzotti Apr 7 '14 at 13:58
  • Well, by golly, you're certainly right about the Powershell insight that I had not considered. I agree that this is a better solution. Thanks! $w = Get-SPWeb "http://localhost/site"; $v = $w.GetViewFromUrl("Lists/MyList/MyView.aspx"); $v.HtmlSchemaXml <-- Can you add that with newlines to your answer for how to do it in powershell? – Jason Kleban Apr 7 '14 at 14:16
  • @MdMazzotti very good answer, but I don't see any problem, from the fact that everybody here assumes their responsability querying the DB, in sharing info about SP database, sometimes a good understanding about DB structure can give you a wider photo of what you are doing. – netadictos Nov 13 '17 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.