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
C# 在featureActivated中获取文件时遇到错误:“;值不在预期范围内”;_C#_Sharepoint_Feature Activation_Spfile - Fatal编程技术网

C# 在featureActivated中获取文件时遇到错误:“;值不在预期范围内”;

C# 在featureActivated中获取文件时遇到错误:“;值不在预期范围内”;,c#,sharepoint,feature-activation,spfile,C#,Sharepoint,Feature Activation,Spfile,我设置将文本文件从模块复制到SharePoint server目录 <?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Module Name="MyModule"> <File IgnoreIfAlreadyExists="TRUE" Path="MyModule\newFile.txt"

我设置将文本文件从模块复制到SharePoint server目录

<?xml version="1.0" encoding="utf-8"?>
 <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <Module Name="MyModule">
    <File IgnoreIfAlreadyExists="TRUE" Path="MyModule\newFile.txt" Url="MyModule/newFile.txt" />
  </Module>
</Elements>
我得到一个例外:“值不在预期范围内”。 我怎么了?

从SharePoint站点获取文件时,properties.Definition.RootDirectory返回本地路径,您将得到异常

我建议您将文件上传到文档库中,就像根web中的“站点资源”,然后在feature receiver中获取文件

示例代码:

Elements.xml

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="MyModule" Url="SiteAssets" RootWebOnly="TRUE">
    <File IgnoreIfAlreadyExists="TRUE" Type="GhostableInLibrary" Path="MyModule\newFile.txt" Url="newFile.txt" />
  </Module>
</Elements>

我不确定你的资产。我不保证在我将要激活我的功能的每个站点中都存在此文档库。您的想法是什么?我们只能将文件上载到根站点的“SiteAssets”中,并从根站点获取文件。检查我的更新回复。您的意思是,我们可以确保根网站中存在我们正在处理的每个网站集的“SiteAssets”文档库?您可以使用PowerShell检查根网站中的该库是否在每个网站集,
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="MyModule" Url="SiteAssets" RootWebOnly="TRUE">
    <File IgnoreIfAlreadyExists="TRUE" Type="GhostableInLibrary" Path="MyModule\newFile.txt" Url="newFile.txt" />
  </Module>
</Elements>
try
{
    SPWeb myWeb = SPContext.Current.Site.RootWeb;
    SPFile newFile = myWeb.GetFile(myWeb.ServerRelativeUrl + "/SiteAssets/newFile.txt");
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}