Setting up Sharepoint files as a visual studio .Net solution

/ Published in: XML
Save to your folder(s)

<strong>Setting up a sp .net soln</strong>

<p>File --&gt; New --&gt; Project</p>
<p>on lefthand side -&gt; Sharepoint -&gt; 2010</p>
<p>usually select an empty template</p>
<p>name the project</p>
<p>to add files, create a module...</p>
<p>right-click project --&gt; add --&gt; new item</p>
<p>select "module"</p>
<p>give the module a name (such as masterpagecatalog)</p>
<p>this will create the module, containing an elements.xml file and open the elements.xml file in code editor. Sample.txt will also be created but may be deleted.</p>

<p>Drag any previously created files that will live in the new module into the module icon in solution explorer</p>

<p>Edit elements.xml. (See example edits to elements.xml in code block further down.) </p>

<p>Edits to make to default xml:</p>

<p>in &lt;Module&gt; tag, put a url (such as Url="_catalogs/masterpage" ) and put RootWebOnly="TRUE"</p>

<p>The &lt;file&gt; tag will also be created with a default url property. Make sure to edit this so that it is correct. By default, it will create a path starting with the name of the module. And if there is no such folder already with that name beneath the Module path, the feature will create one. The actual path is designated by both the &lt;module&gt; url property and the &lt;file&gt; url property (that is, both of those properties are combined).</p>

<p>Add Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" to the &lt;file&gt; elements. IgnoreIfAlreadyExists="TRUE" means "overwrite existing file". Type="GhostableInLibrary" setting is used when a file is placed into a library. If a file is placed outside of a library, Type="Ghostable" would be used.</p>

<p>Change the &lt;file&gt; tags so that it is not self-closing.</p>

<p>Add some Property tags.Columns in the master page correspond to file object properties indicated in the module xml. Other file properties in the xml will also be added to the "property bag" that do not correspond to master page columns (see &lt;property&gt; tags above). </p>

<p>First, it is good practice to always add
&lt;Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/&gt;</p>

<p>On compliation, Value="$SharePoint.Feature.Id$" will be replaced with guid of feature. </p>

<p>For a master page, the following metadata will be added via the property tags</p>

<p>&lt;Property Name="UIVersion" Value="4" /&gt; </p>
<p>&lt;Property Name="ContentTypeId" Value="0x010105" /&gt;</p>
<p>&lt;Property Name="ContentType" Value="$Resources:cmscore,contenttype_masterpage_name;" /&gt;</p>
<p>&lt;Property Name="MasterPageDescription" Value="Masterpage for SepulvedaPOC sites." /&gt; </p>

<p>Make sure to edit the description as appropriate.</p>

<p>When the module was created, VS automatically created a feature called "Feature 1". Note that features may also be created by right-clicking "Features" in soln explorer and selecting "Add Feature".</p>

<p>Next step: add event reciever feature activated code if necessary</p>

<p>* Make sure to add the proper modules to the feature
* Make sure that Scope is set to "Site" in the feature if the solution is a sandbox solution</p>

Copy this code and paste it in your HTML
  1. <!-- ### Example edits to elements.xml ### -->
  2. <!--Here is an example of an edited file for a master page...-->
  4. <?xml version="1.0" encoding="utf-8"?>
  5. <Elements xmlns="">
  6. <Module Name="masterpagecatalog" Url="_catalogs/masterpage" RootWebOnly="TRUE">
  7. <File Path="masterpagecatalog\LLC.master" Url="LLC.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE">
  8. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  9. <Property Name="UIVersion" Value="4" />
  10. <Property Name="ContentTypeId" Value="0x010105" />
  11. <Property Name="ContentType" Value="$Resources:cmscore,contenttype_masterpage_name;" />
  12. <Property Name="MasterPageDescription" Value="Masterpage for Learning Center." />
  13. </File>
  14. </Module>
  15. </Elements>
  17. <!--And here is an example of an edited file that places files into three different subfolders within the Style Library...-->
  19. <?xml version="1.0" encoding="utf-8"?>
  20. <Elements xmlns="">
  21. <Module Name="StyleLibrary" Url="Style Library" RootWebOnly="TRUE">
  22. <File Path="StyleLibrary\lilly_main.css" Url="Lilly/lilly_main.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  23. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  24. </File>
  25. <File Path="StyleLibrary\lessons.js" Url="Scripts/lessons.js" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  26. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  27. </File>
  28. <File Path="StyleLibrary\banner-outlook-rm.jpg" Url="Lilly/images/banner-outlook-rm.jpg" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  29. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  30. </File>
  31. <File Path="StyleLibrary\bg-persChoiceBottom.jpg" Url="Lilly/images/bg-persChoiceBottom.jpg" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  32. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  33. </File>
  34. <File Path="StyleLibrary\bg-persChoiceMid.jpg" Url="Lilly/images/bg-persChoiceMid.jpg" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  35. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  36. </File>
  37. <File Path="StyleLibrary\bg-persChoiceTop.jpg" Url="Lilly/images/bg-persChoiceTop.jpg" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  38. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  39. </File>
  40. <File Path="StyleLibrary\new-window.png" Url="Lilly/images/new-window.png" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  41. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  42. </File>
  43. </Module>
  45. </Elements>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.