如何确定文件是否存在于 SharePoint SPFolder 中 [英] How to determine if a file exists in a SharePoint SPFolder

查看:40
本文介绍了如何确定文件是否存在于 SharePoint SPFolder 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了循环遍历 SPFolder 中的文件之外,还有其他方法可以确定给定的文件名(字符串)是否存在?

Is there a way other than looping through the Files in a SPFolder to determine if a give filename (string) exists?

推荐答案

如果您知道 URL,也可以使用 SPFile.Exists 属性,如下所示:

You can, if you know the URL also use the SPFile.Exists property as follows:

using (SPSite site = new SPSite("http://server/site"))
using (SPWeb web = site.OpenWeb())
{
  SPFile file = web.GetFile("/site/doclib/folder/filename.ext");
  if (file.Exists)
  {
    ...
  }
}

如果文件不存在,人们首先会认为 SPWeb.GetFile 会抛出异常.但正如您所见,情况并非如此——它实际上会返回一个 SPFile 对象.

One would on first thought assume SPWeb.GetFile throws an exception if the file does not exist. But as you see this is not the case - it will actually return a SPFile object.

这篇关于如何确定文件是否存在于 SharePoint SPFolder 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆