1
我想允許匿名用戶上傳SharePoint中的文件。 經過一番研究,我編寫了這個代碼,允許匿名用戶上傳。但匿名用戶無法登錄並被要求登錄。 請幫助我。我的代碼有什麼問題?如何在SharePoint中爲匿名用戶允許文件上傳
public string CreateSPFilet(string spServerURL, string tempLibrary, string folder, Stream fileStream, bool overwrite)
{
string strError = "";
string fileName = "";
try
{
if (!SPSite.Exists(new Uri(spServerURL)))
{
strError += ERROR01;
}
else
{
SPSite tempSite = new SPSite(spServerURL);
SPUserToken systoken = tempSite.SystemAccount.UserToken;
using (SPSite site = new SPSite(spServerURL, systoken))
{
SPWeb oWebsite = site.OpenWeb();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedSite = new SPSite(site.ID))
{
using (SPWeb eevatedWeb = elevatedSite.OpenWeb(oWebsite.ID))
{
oWebsite.AllowUnsafeUpdates = true;
string targetUrl = SPUrlUtility.CombineUrl(oWebsite.ServerRelativeUrl, tempLibrary);
SPFolder target = oWebsite.GetFolder(targetUrl);
SPFileCollection files = target.Files;
SPFile file = target.Files.Add(fileName, fileStream, overwrite);
oWebsite.AllowUnsafeUpdates = false;
}
}
});
}
}
非常感謝。 我沒有注意到它! D: – kevin 2012-04-18 09:58:16