Search This Blog

Wednesday, April 6, 2011

Deploy files to 12 hive with webpart solution using VSewss

You can deploy various files like .jpg, gif, css, javascript etc along with your WebPart solution package using <Templatefiles>tag, avilable in your solution's manifest.xml file.
You however, do not modify the <TemplatesFile> tag directly, instead you would mimic the 12 hive folder structure in your webpart and will add the files that you want to deploy under the structure. The Template files tag in manifest file will automatically be created by Vsewss once you build the solution. See the detailed example below.

Please Note : If you want to create a solution package for just deploying some files in 12 hive, for e.g. deploying custom aspx page or layouts page or Custom css or javascript file then see the Related Post :Deploy Custom Css file in 12 hive as solution package
Below are the Steps to deploy some additional files in SharePoint's 12 hive with your webpart solution package. Also, note that the WebPart used in the below example was created using WebPart template available with VSeWSS.

Step 1: Create the Template Directory structure in your webpart Project. For e.g to deploy your css or Image files in 12 hive's STYLES library, Create a folder structure as
Templates->LAYOUTS->1033->STYLES->Your custom Folder. Now, add your files under your Custom Folder.
See the screen below


Step 2: Build the WebPart.

Now, open manifest.xml and look at the tag <TemplateFiles>. You will notice that VSeWSS has added entries for all the files in your custom folder as TemplateFiles. This defines the Path where these files will be deployed. See the Image below.


Step 3: Now, deploy the Solution.
Step 4 : Verify that the Folder "MyCustomWebPart"(your custom folder name) is available in the Styles folder.

If you want to use the deployed Images in your WebPart, you can simply use it with below url
_LAYOUTS\1033\STYLES\MyCustomWebPart\img.jpg."

For details on how to register and use Css and Javascript files in your webpart,see the post

Using External CSS, Javscript or Images in a WebPart

Below Code is to ensure that your webpart gets removed from WebPart gallery during retraction. This is done by adding a Feature receiver in your webpart solution file.

Step 4: Create a FeatureReceiver.cs class file. Add the below code for feature deactivating.

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite site = null;
try
{
site = properties.Feature.Parent as SPSite;
using (SPWeb web = site.RootWeb)
{
SPList list = web.Lists["Web Part Gallery"];
// go through the items in reverse
int count = Convert.ToInt32(list.ItemCount);

for(int i = count -1 ;i>= 0; i--)
{
// format name to look like a feature name

string webpartName = list.Items[i].Name;

webpartName = webpartName.Substring(0, webpartName.IndexOf('.'));

// delete web parts that have been added

if (properties.Feature.Definition.DisplayName == webpartName)
{
list.Items[i].Delete();
break;
}
}

}

}

finally
{
if (site != null)
site.Dispose();
}
}

Now, add an entry for Feature receiver in your feature.xml. Specify the ReceiverAssembly and the receiver class. Build the Project. see fig below :


Step 4 : Retract the solution from central Admin -> operations -> solution managment.
Verify that the Custom folder in STYLES library is removed.

Note : If you custom folder with Images is deployed in Templates->LAYOUTS->1033->IMAGES folder,It wont get removed on
retracting the solution. The Images which are deployed directly in the Templates->LAYOUTS->1033->IMAGES folder gets retracted. For more on Template files and other options in manifest.xml .

19 comments:

  1. Hello there, just became alert to your blog through Google, and found that it's truly informative. I'm going to watch out for brussels.
    I'll be grateful if you continue this in future. Numerous people will be benefited from your writing. Cheers!
    Have a look at my homepage - efiree.com

    ReplyDelete
  2. Hello there I am so thrilled I found your webpage, I really
    found you by error, while I was searching on Google for something else, Anyways I am here now and
    would just like to say kudos for a fantastic post and a all round thrilling
    blog (I also love the theme/design), I don’t have time to read through it all at the moment but I have book-marked it and also included your RSS feeds, so when I have time
    I will be back to read much more, Please do keep up the excellent jo.
    Here is my page :: http://www.groundplanet.com

    ReplyDelete
  3. I do not even know how I ended up here, but I thought this post was good.
    I do not know who you are but definitely you're going to a famous blogger if you are not already ;) Cheers!
    Feel free to surf my web page ; radio.km5.com.br

    ReplyDelete
  4. Thanks very interesting blog!

    Here is my homepage: check this out

    ReplyDelete
  5. I'm curious to find out what blog platform you happen to be working with? I'm experiencing some small security issues with my
    latest blog and I'd like to find something more safe. Do you have any suggestions?

    Feel free to surf to my homepage :: easterhegg.ch

    ReplyDelete
  6. I go to see day-to-day a few web pages and blogs to read
    articles or reviews, except this weblog gives quality based posts.



    Here is my site: affordable seo Services

    ReplyDelete
  7. You could certainly see your expertise in the work you write.
    The sector hopes for more passionate writers like you who aren't afraid to say how they believe. Always go after your heart.

    Also visit my web page; http://esponjadelufa.com/

    ReplyDelete
  8. We stumbled over here coming from a different web address and thought
    I should check things out. I like what I see
    so now i'm following you. Look forward to looking at your web page for a second time.

    my page; torontowineeducation.com

    ReplyDelete
  9. Fine way of telling, and nice piece of writing
    to obtain information concerning my presentation subject, which i am
    going to convey in university.

    my website :: Baby Clothing Distributor

    ReplyDelete
  10. Thanks for one's marvelous posting! I really enjoyed reading it, you could be a great author.I will remember to bookmark your blog and will come back later in life. I want to encourage you to definitely continue your great posts, have a nice morning!

    Here is my homepage: http://wiki.gambserv.com/index.php?title=Utilisateur:AlfredLuc

    ReplyDelete
  11. Great information. Lucky me I found your site by chance (stumbleupon).
    I've saved it for later!

    Feel free to visit my page; korillolatino.com

    ReplyDelete
  12. What a information of un-ambiguity and preserveness of valuable know-how regarding
    unexpected emotions.

    Also visit my site ... cuoihoinet.vn

    ReplyDelete
  13. Nice blog here! Also your site lots up very fast!
    What web host are you the usage of? Can I am getting your affiliate link on your host?
    I wish my website loaded up as quickly as yours lol

    Look at my web page; http://azonbundlereview.com/top-5-coolest-indie-clothing-online-stores/

    ReplyDelete
  14. I just couldn't leave your web site prior to suggesting that I extremely enjoyed the standard information an individual supply on your guests? Is going to be back continuously to investigate cross-check new posts

    Here is my web-site; click through the up coming article

    ReplyDelete
  15. Hurrah, that's what I was seeking for, what a stuff! present here at this blog, thanks admin of this web page.

    Take a look at my page; just click the next document

    ReplyDelete
  16. I loved as much as you'll receive carried out right here. The sketch is attractive, your authored material stylish. nonetheless, you command get bought an shakiness over that you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly very often inside case you shield this increase.

    Also visit my weblog; 1980designs.com

    ReplyDelete
  17. First of all I would like to say great blog! I had a quick
    question in which I'd like to ask if you don't mind.
    I was curious to find out how you center yourself and clear your head prior to writing.

    I have had a hard time clearing my mind in getting my
    ideas out. I do enjoy writing however it just seems like the first
    10 to 15 minutes are usually wasted just trying to figure out how to begin.

    Any suggestions or tips? Many thanks!

    Stop by my blog; http://www.flokib.at/

    ReplyDelete
  18. Yesterday, while I was at work, my sister stole my apple
    ipad and tested to see if it can survive a 25 foot drop, just so she can be a
    youtube sensation. My iPad is now broken and she has 83 views.

    I know this is completely off topic but I had
    to share it with someone!

    My website :: http://www.besteyecreamfordarkcircles.net/lifestyle/the-issue-of-spending-on-baby-clothing

    ReplyDelete
  19. certainly like your website but you have to take a look
    at the spelling on quite a few of your posts.
    Several of them are rife with spelling problems and I
    to find it very troublesome to inform the truth
    on the other hand I'll certainly come again again.

    Feel free to visit my blog ... Sakura.Ne.Jp

    ReplyDelete