- In your SharePoint Project, create folder "App_Themes"
- Inside that folder create a sub folder with name "Default" (we use Default for skin name)
-
Add text file item into that folder and name it Default.skin (filename should be same with its folder)
-
Add control you want to skin, for this example I'll use TextBox with SkinID "DefaultInput"
<asp:TextBox runat="server" SkinID="DefaultInput" Width="200px"></asp:TextBox>
- As you can see I only add folder and not special SharePoint folder that will be packaged inside wsp file. This folder won't get deployed whenever we deploy this project and want to apply some skin, we need to get around with this problem.
- Skin files need to be put under IIS root. We could copy it manually into SharePoint folder inside wwwroot but I prefer creating cmd files that will copy it.
-
Again add text file item and give it a name and add extension .cmd, I'll name it "DeploySkinFile.cmd"
-
Insert this dos command into that file, this command will copy all files under App_Themes folder to "C:\inetpub\wwwroot\wss\VirtualDirectories\80"
SET ACTIVEDIR=%1 SET TARGETASP=C:\inetpub\wwwroot\wss\VirtualDirectories\80 cd %ACTIVEDIR% IF not exist %TARGETASP%\App_Themes ( md %TARGETASP%\App_Themes ) xcopy App_Themes %TARGETASP%\App_Themes /E /G /Y
- We need to run this automatically when we built this project. Right click on Project name -> Properties to open its properties window and head to "Build Events" tab
-
Add this command under "Post-build event command line"
"$(ProjectDir)DeploySkinFile.cmd" "$(ProjectDir)"
-
We need to tell aspx to use this skin file, this can be done on page directive or on pages tag inside web.config. Since I'm using this for visual web part, I'm going to put it inside web.config. Open web.config under root folder of SharePoint, add this on the last tag pages
-
Let's create a visual web part with textbox control and SkinID="DefaultInput" to test this.
-
Now deploy the project and add that visual web part. Browse to it and view the source, the textbox will have width 200px as defined in skin file above
This is my personal blog to store all my experience as a SharePoint developer. I work mostly on developing 'In-House' solution that use Asp.net which run on top of SharePoint. I've experienced in developing this solution from SharePoint 2007, 2010, 2013 and 2016.
Thursday, 28 May 2015
Using skin file in SharePoint Project
Building many custom input form for SharePoint which use many control style/configure can be tedious work. Especially if you have many developer working on the same project. CSS can be used for this purpose, but it work for general and not specific to styling certain control. ASPX have skin file that can be used for theme in web application project and it is for specific control. I've experimented on how to add this skin file to SharePoint project and use that skin feature for our SharePoint visual web part. This is how I've done it to make our project use skin file for configuring and styling web control easier.
Labels:
ASPX,
SharePoint 2013,
Skin
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment