Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sharepoint 功能事件具有';空';物体_Sharepoint_Sharepoint 2010 - Fatal编程技术网

Sharepoint 功能事件具有';空';物体

Sharepoint 功能事件具有';空';物体,sharepoint,sharepoint-2010,Sharepoint,Sharepoint 2010,该功能已成功安装(日志中没有错误)。我的问题是sContextNull总是返回“Context is NULL”。而且sFeatureNull也总是返回“Feature is NULL”。是否有方法获取SPContext.Current和properties.Feature的非空值 另一个方法FeatureActivated返回上下文为空且功能为OK。WTF?SPContext.Current 获取微软SharePoint基金会中当前HTTP请求的上下文。< /C>>/P> SPFeatur

该功能已成功安装(日志中没有错误)。我的问题是sContextNull总是返回“Context is NULL”。而且sFeatureNull也总是返回“Feature is NULL”。是否有方法获取SPContext.Currentproperties.Feature的非空值

另一个方法FeatureActivated返回上下文为空且功能为OK。WTF?

SPContext.Current

<代码>获取微软SharePoint基金会中当前HTTP请求的上下文。< /C>>/P>


SPFeatureReceiver.FeatureInstalled
在将功能安装到服务器场时执行,这是通过stsadm或powershell的部署/安装命令完成的,然后通常触发计时器作业来执行该工作。此时没有HTTP请求,因此SPContext.Current返回null。

可能是属性。方法FeatureInstalled中的功能是一个bug。我尝试了下一个代码,它对我有效:

public class Feature1EventReceiver : SPFeatureReceiver
{

    public override void FeatureInstalled(SPFeatureReceiverProperties properties)
    {

        string sContextNull = (SPContext.Current == null) ? "Context is NULL" : "Context is OK";
        string sFeatureNull = (properties.Feature == null) ? "Feature is NULL" : "Feature is OK";

        // Some code here
        ...
        ...
    {
}
此方法返回功能正常


请避免在方法FeatureInstalledFeatureUninstalling中使用属性。功能

我认为您需要获得包含此功能的web,因此请尝试使用

public class Feature1EventReceiver : SPFeatureReceiver
{    
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {    
        string sFeatureNull = (properties.Feature == null) ? "Feature is NULL" : "Feature is OK";

        // Some code here
        ...
        ...
    {
}
它对我很管用


注意:如果功能范围是站点,请尝试将其转换到SPSite

谢谢!什么是properties.Feature?您可以尝试调试该事件,这似乎与您的问题相同。没有人知道answerproperties。FeatureInstalled中的功能为空。出于您尝试使用它的目的,为了获取properties.Feature.Parent,它无论如何都没有用处。下面的建议——使用FeatureActivated——可能是你最好的选择。如果您正在执行不需要SPSite或SPWeb上下文的操作,则FeatureInstalled将起作用。
(properties.Feature.Parent as SPWeb)