zoukankan      html  css  js  c++  java
  • 使用JSOM检查文件或文件夹是否存在

    How to Check with SharePoint JSOM if File or Folder Exists

    Here’s a code snippet showing how to use SharePoint’s JavaScript Object Model (JSOM) to determine whether a file or folder exists:

    var ctx = SP.ClientContext.get_current();
     
    // Could also call getFileByServerRelativeUrl() here. Doesn't matter.
    // The way this works is identical for files and folders.
    var folder = ctx.get_web().getFolderByServerRelativeUrl("/path/to/folder");
     
    ctx.load(folder, "Exists", "Name");
     
    ctx.executeQueryAsync(
       function() {
          if (folder.get_exists()) {
             // Folder exists and isn't hidden from us. Print its name.
             console.log(folder.get_name());
          }
          else {
             console.log("Folder exists but is hidden (security-trimmed) for us.");
          }
       },
       function(s, args) {
          if (args.get_errorTypeName() === "System.IO.FileNotFoundException") {
             // Folder doesn't exist at all.
             console.log("Folder does not exist.");
          }
          else {
             // An unexpected error occurred.
             console.log("Error: " + args.get_message());
          }
       }
    );

    The behavior of the client-side object model is slightly different depending whether the file or folder truly doesn’t exist or is just being hidden from us due to security-trimming.

    The code snippet above takes this distinction into account and shows you how to check for both conditions.

    You can also issue a CAML query against a document library (if that’s where your file/folder lives) to see if an item representing your file/folder exists, but the above snippet is intended to demonstrate the procedure for actual SP.File and SP.Folder objects.

    原文地址:https://yieldreturnpost.wordpress.com/2015/08/25/how-to-check-with-sharepoint-jsom-if-file-or-folder-exists/

  • 相关阅读:
    运营商公网
    任务管理器 的 服务与进程
    QQ通信原理及QQ是怎么穿透内网进行通信的?
    windows Telnet 客户端常用命令介绍
    redis优化
    shell反射
    USB安装centos6系统(centos7需要换软件)
    rocketmq双主模式
    golang数据类型与转换
    golang介绍
  • 原文地址:https://www.cnblogs.com/bjdc/p/6256680.html
Copyright © 2011-2022 走看看