kamagra how much to take

Use Freakin GetClassResourcePath()!

God, if I see one more hardcoded image/CSS/JS file in a WebPart pointing to some custom image directory in the 12 hive I am going to murder myself. Jesus, it drives me nuts. Why? Because it means that when the magical little red X comes up I have to RDC to the server and set the permissions for your stupid image.

I might hate it as much as Snap!, I am not sure. So, my recommendation is if you are writing WebParts for SharePoint, you should use GetClassResourcePath(). This is pretty easy whether you are doing ASP.NET 2.0 or SharePoint WebParts.I have gotten the feedback that GetClassResourcePath doesn’t exists in ASP.NET 2.0 WebParts, which is not true since the SPWebPartPageManager class houses the static GetClassResourcePath method.

So, the GetClassResourcePath just returns a string, so if you want you could declare it first by setting up the proper exception handling for the string return:

  1. public string GetClassResourcePath()
  2. {
  3. try
  4. {
  5. return base.ClassResourcePath;
  6. }
  7. catch (Exception exception)
  8. {
  9. return exception.ToString();
  10. }
  11. }

Then you can consume it wherever you want. As an example, say you want to call a CSS sheet with GetClassResourcePath. First just declare that you are using your fancy new method to assign the string the resource value:

  1. string myWebPartPath = wp.GetClassResourcePath();

Then actual use the declaration however you want.

  1. protected override void RenderWebPart(HtmlTextWriter output)
  2. {
  3.  
  4. string myWebPartPath = wp.GetClassResourcePath();
  5. this.EnsureChildControls();
  6. RenderChildren(output);
  7. output.Write("
  8. <link xhref='{0}/my.css' rel='stylesheet'/>", myWebPartPath);
  9. }

So don’t hardcode resources into your WebParts. It makes you a bad person.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>