views:

309

answers:

4

Hi all:

Currently I'm having trouble adding custom/my own css files to my SharePoint site. I add the custom/my own css files via the c# files (CssLink) as a web part and have them applied to my site's javascript files. Trouble is, whenever the css files were applied, my site goes back to the default blue-ish SharePoint theme color.

Is there any quick and simple way to avoid that from happening?

Thanks.

A: 

Why don't you use, Site Settings, Master page and use the option "Specify a CSS file to be used by this publishing site and all sites that inherit from it." to specify your own CSS.

(Also, I have no idea what you mean with "via the c# files (CssLink) as a web part and have them applied to my site's javascript files". Are you missing some words in that sentence?)

ArjanP
+1  A: 

You can use this method to register a css file from a WebPart

Microsoft.SharePoint.WebControls.CssRegistration.Register("/.../mystyles.css")

or you can add the css file to the content place holder with the id "PlaceHolderAdditionalPageHead" which is present in the master page like this

var placeholder= Page.FindControl("PlaceHolderAdditionalPageHead");
var cssLink = new Literal();
cssLink.Text = "text";
placeholder.Controls.Add(cssLink);
iHeartDucks
@iHeartDucks: instead of using the code example you provided, I putted the links of the css in the default.aspx's PlaceHolderAdditionalPageHead. For now, it works. Thanks.
BeraCim
A: 

You should have a very good reason to be adding CSSLink via C#. Have you considered packaging your CSS as your own theme?

SharePoint themes are easy to create and have many benefits such as: a) Supported by Microsoft b) Easy to create c) Manageable by the end users. d) You can apply different themes to different parts of the site. e) etc etc...

The process of creating the theme can be found here: http://sharepoint.microsoft.com/blogs/GetThePoint/Lists/Posts/Post.aspx?ID=122

I would recommend adding your theme via a feature only for adding and removing the theme. This would add a great deal of options for future tweaking. Here is an example: http://www.devexpertise.com/2009/02/11/installing-a-theme-as-a-sharepoint-feature/

I'm going to blog about this later this week so keep an eye out of you like. http://blog.zebsadiq.com

Zeb
@Zeb: I used the CSSLink in the c# code, and that was what failed me. My site turned back to the default blue theme as soon as the CSSLinks get loaded.
BeraCim
A: 

Upload your css in the syle library folder(or any library in side your site) go to -->site actions-->site settings-->modify all site settings-->under look and feel tab-->click master page-->there is one option called alternate css url-->browse your custom css and click Ok.

Radhika