C# 在featureActivated中获取文件时遇到错误:“;值不在预期范围内”;
我设置将文本文件从模块复制到SharePoint server目录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"
<?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);
}