how to set image which is in images folder of the project to newPage.ListItem[FieldId.PublishingPageImage] = image in the folder;
Will the image get loaded to provisioned site when a site is provisioned?
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityhow to set image which is in images folder of the project to newPage.ListItem[FieldId.PublishingPageImage] = image in the folder;
Will the image get loaded to provisioned site when a site is provisioned?
You'll need to have the image already uploaded somewhere on your site. You can do this manually or if you have the image in a VS project, you can deploy it with a module.
Then set the URL for your publishing image field
ImageFieldValue pageImage = newPage.ListItem[FieldId.PublishingPageImage] as ImageFieldValue;
if (null == pageImage)
pageImage = new ImageFieldValue();
pageImage.ImageUrl = "http://yoursite/yourimage.jpg";
newPage.ListItem[FieldId.PublishingPageImage] = pageImage;
newPage.Update();
If you add SharePoint "Images" Mapped Folder
to your project and add your image to that mapped folder, Visual Studio will automatically deploy it with your wsp. The url to a file in the images mapped folder is "_layouts/images/your-image.jpg"
If you want an image deployed to another location (not TEMPLATE\IMAGES), you can create a module and add your image to that module. This will cause Visual Studio to add a from/to entry to the module's element manifest. For example if you wanted the image to go into the Style Library of your site, it would look like this:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="your module name" Url="Style Library" RootWebOnly="FALSE">
<File Path="path-in-your-VS-project\your-image.jpg" Url="your-image.jpg" Type="GhostableInLibrary" />
</Module>
</Elements>