1

i'm stuck for hours now to figure out how the heck i can get my Stylesheets into my Webpart. Now i've found several resources claiming on how it works

Now the first one works. But it shouldn't really be needed to manually place a single CSS File in a specific folder on each System (Dev, Test, Live). There has to be a way to embedd the Webpart into the deployment file for the project.

Searching for this i came up with the second link i've posted. This pretty much LOOKS like something i wanna do, but i simply can not get it to work.

My Structure is the following:

./SOLUTION
  > Properties
  > References
  > ...
  > Webpart1
    > ...
  > Webpart2
    > Webpart2.css
    > ...
  > Styles (A Folder of VS Style 'Module')
    > wp2.css

Would someone be so kind to tell me how i can include the wp2.css into the sharepoint page only if the webpart is visible on the page. Without the need of me manually needing to place the css file as pointed out in link 1.

Thanks a lot in advance!

1
  • Are you asking how to set up a Web Part project so the CSS file is added to the WSP package? Commented Dec 23, 2011 at 11:06

1 Answer 1

1
  1. Add the Layouts mapped folder to the solution (How to: Add and Remove Mapped Folders).
  2. Create appropriate folder structure inside (e.g. /1033/styles) and copy the CSS file there.
  3. Build the WSP package - the CSS file will be placed inside and copied to the [14 hive]\TEMPLATE\LAYOUTS\1033\styles folder once the package is deployed.
Sign up to request clarification or add additional context in comments.

3 Comments

Great, thanks! This greatly helpes me. I did the above (though i didn't create additional folder structure (/1033/styles). Then i just needed to add CssRegistration.Register("/_layouts/MyProjectName/wp2.css"); and it all worked! Thanks a lot!
Creating the folder structure is an optional step - I usually do it to keep all the custom CSS files is a separate folder and therefore be able to keep track of them easily.
Okay, but isn't that already the case with Visual Studio creating a subfolder for your Project? /Layouts/MyProjectName/file.css. Alternatively though - i agree with that point - making one more 'grouped' folder above like /Layouts/AllCustoms/MyProjectName/file.css might be a good thing to do. Thanks for the advice, its appreciated a lot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.