开发者

Include .STP file as feature to create .WSP file

I have to give the client a .wsp file

Please give me an example of how to include the .stp inside the feature and include that feature along with other files to create a .wsp file.

I have gone thru lots of site where they show the steps but I dont understand how to approach as I have got different files like .dlls files, custom event receivers features, custom web part and site template .stp file all th开发者_如何学JAVAis I need to include. I need one exampkle where I can see the exact elements name or syntax of manifest.xml file. For eg: to include and delpy the .dll files we use assembly element and similary for features FeaturesMainfest element like that I need one example of other elements where I can wrap all the files to create a .wsp package

Please help me on this Thanks Abdul Afroze


Abdul,

Have a look at the following example. This will be your main manifest.xml file.

    <?xml version="1.0" encoding="utf-8"?>
<!-- Solution created by WSPBuilder. 10/21/2010 11:22:17 AM  -->
<Solution xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SolutionId="c0096412-9324-4bc5-a411-652d319efe59" xmlns="http://schemas.microsoft.com/sharepoint/">
  <FeatureManifests>
    <FeatureManifest Location="xxxxxxx\feature.xml" />
  </FeatureManifests>
  <Assemblies>
    <Assembly Location="xxxxxxxxxxxx.dll" DeploymentTarget="GlobalAssemblyCache" />
  </Assemblies>
  <TemplateFiles>
    <TemplateFile Location="LAYOUTS\xxxxxxx\xxxxxxx.asmx" />
  </TemplateFiles>
  <Resources>
    <Resource Location="xxxxxxx\ListTemplates\xxxxxxx.stp" />
  </Resources>
</Solution>

And in your feature recivers class you need to upload the template file to the template document library. Here is a very simple example.

private void UploadTemplates(SPDocumentLibrary templateGallery, string[] templateFiles)
        {
            try
            {
                if (templateGallery != null)
                {
                    foreach (string str in templateFiles)
                    {

                    FileInfo info = new FileInfo(str);
                    SPQuery query = new SPQuery();
                    query.Query = string.Format("<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='Text'>{0}</Value></Eq></Where>", info.Name);
                    SPListItemCollection items = templateGallery.GetItems(query);
                    int[] numArray = new int[items.Count];
                    for (int i = 0; i < items.Count; i++)
                    {
                        numArray[i] = items[i].ID;
                    }
                    for (int j = 0; j < numArray.Length; j++)
                    {
                        templateGallery.Items.DeleteItemById(numArray[j]);
                    }
                    byte[] file = File.ReadAllBytes(str);
                    templateGallery.RootFolder.Files.Add(info.Name, file);
                }
            }
            else
            {
                 // templateGallery is null
            }
        }
        catch (Exception exception)
        {
          // handle your errors
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜