When I met with SPS manipulating files (delete) of such a problem, there will be problems when using the following code to delete the site root of the file, but not delete a file in the subdirectory of the site; upload the file to the root directory of the site also It will be problems, but it will not be uploaded to a subdirectory:
name Space MMXSPS
{
class SPSAccess
{
........
/// <the Summary>
/// delete the specified files in a specified folder
/// </ Summary>
/// <param name = "strSiteName"> site file is located: siteName ---- Example: "/ sites / SiteName" </ param>
/// <param name = "strFolder"> file file resides folder: folderName ---- Example: "/ Sites / SiteName / FolerPath </ param>
/// <param name =" strFileName "> file name: filename.htm </ param>
public BOOL the DeleteFile (strSiteName String, String strFolder , String strFileName)
{
String = strServerURL the this.SPServerURL;
try
{
strSiteName=strSiteName;
SPWeb Myweb=new SPSite(strServerURL).AllWebs[strSiteName];
Myweb.AllowUnsafeUpdates=true;
string strNewUrl1;
if (Myweb.GetFolder(strFolder).Exists)
{
SPFileCollection delFiles = Myweb.GetFolder(strFolder).Files;
strNewUrl1=strServerURL + strFolderPath + "/" + strFileSaveToName;
if(site.GetFile(strNewUrl1).Exists) //会出错
delFiles.Delete(strFolder+"/"+strFileName);
}
return true;
}
catch(Exception msg)
{
this._ErrorMessage=msg.Message.ToString();
return false;
}
}
.......
public string Upload(string strSiteName,string strFolder,string strFileName)
{
SPFileCollection spfc;
......
strNewUrl1=strServerURL + strFolderPath + "/" + strFileSaveToName;
upFile = spfc.Add(strNewUrl1, ConvertToStream(InputFileStream));//会出错
......
}
.......
public byte[] ConvertToStream(Stream fStream)
{
....
}
}
}
I do not know why this is so? ? ?
Reproduced in: https: //www.cnblogs.com/llbofchina/archive/2005/08/20/219145.html