我现在可以使用gacutil.exe和sn.exe将我的HelloWorld.dll导入GAC,并将其上传到SharePoint。 我可以在功能列表中看到它。 但是,当我尝试激活它时,我得到:
Feature '79bc44ea-93f5-4886-8784-8f3fbd1dfa48' could not be installed because the loading of event receiver assembly "HelloWorld, Version 1.0.0.0, Culture=neutral, PublicKeyToken=b169cb5c722a4763" failed: System.IO.FileLoadException: Could not load file or assembly 'HelloWorld\, Version 1.0.0.0\, Culture\=neutral\, PublicKeyToken\=b169cb5c722a4763' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
File name: 'HelloWorld\, Version 1.0.0.0\, Culture\=neutral\, PublicKeyToken\=b169cb5c722a4763'
at System.Reflection.AssemblyName.nInit(Assembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()
这是一个新手功能,它有一个事件处理程序,我的feature.xml文件:
<Feature
Id="79bc44ea-93f5-4886-8784-8f3fbd1dfa48"
Title="Hello World Feature"
Description="This is my first custom Featuree"
Scope="Web"
Hidden="False"
ImageUrl="menuprofile.gif"
ReceiverAssembly="HelloWorld, Version 1.0.0.0, Culture=neutral, PublicKeyToken=b169cb5c722a4763"
ReceiverClass="HelloWorld.FeatureReceiver"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>
我的elements.xml文件:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="SiteActionsToolbar"
GroupId="SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="100"
Title="Hello World"
Description="A custom menu item added using a Feature"
ImageUrl="_layouts/images/menuprofile.gif">
<UrlAction Url="http://msdn.microsoft.com"/>
</CustomAction>
</Elements>
当我运行sn.exe时,dll有效,并且它在GAC中。由于事件处理程序,我确实有一个.cs文件,我假设它在dll中? 如果我编写功能“Id”是否重要,我只是从我正在使用的代码示例中复制了一个数字。 我可以研究其他一般领域吗?
这是接收器类:
using System;
using Microsoft.SharePoint;
namespace HelloWorld
{
public class FeatureReceiver : SPFeatureReceiver
{
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
}
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
Console.WriteLine("...in HelloWorld.FeatureActiviated()...");
SPWeb site = (SPWeb)properties.Feature.Parent;
site.Properties["OriginalTitle"] = site.Title;
site.Properties.Update();
site.Title = "Hello World";
site.Update();
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPWeb site = (SPWeb)properties.Feature.Parent;
site.Title= site.Properties["OriginalTitle"] = site.Title;
site.Update();
}
}
}
答案 0 :(得分:0)