コード例 #1
0
        public SPOFile GetFile(string fileName)
        {
            var file = _folder.Files.GetByUrl(fileName);

            SPOFile.LoadFile(SPOSiteContext.CurrentSiteContext.Context, file);
            return(new SPOFile(file));
        }
コード例 #2
0
        public SPOFile AddFile(byte[] content, bool overwrite, string leafName, Dictionary <string, object> fieldValues)
        {
            FileCreationInformation fci = new FileCreationInformation();

            fci.Content   = content;
            fci.Overwrite = overwrite;
            fci.Url       = leafName;
            File     file = _folder.Files.Add(fci);
            ListItem item = file.ListItemAllFields;

            if (fieldValues != null)
            {
                foreach (string fieldName in fieldValues.Keys)
                {
                    item[fieldName] = fieldValues[fieldName];
                }
            }
            item.Update();

            _folder.Context.ExecuteQuery();

            SPOFile.LoadFile(SPOSiteContext.CurrentSiteContext.Context, file);

            return(new SPOFile(file));
        }
コード例 #3
0
        internal SPOFile AddTemplateFile(string leafName, TemplateFileType templateType, bool throwIfExists)
        {
            if (string.IsNullOrEmpty(leafName))
            {
                throw new ArgumentNullException("The leafName name cannot be null.");
            }
            if (!leafName.ToLower().EndsWith(".aspx"))
            {
                leafName += ".aspx";
            }

            SPOFile existingFile = null;

            try
            {
                existingFile = GetFile(leafName);
            }
            catch { }
            if (existingFile != null && existingFile.Exists)
            {
                if (throwIfExists)
                {
                    throw new FileExistsException("The specified file already exists.");
                }

                return(existingFile);
            }

            string url  = ServerRelativeUrl.TrimEnd('/') + "/" + leafName;
            var    file = _folder.Files.AddTemplateFile(url, templateType);

            SPOFile.LoadFile(SPOSiteContext.CurrentSiteContext.Context, file);
            return(new SPOFile(file));
        }
コード例 #4
0
        public SPOFile GetFile()
        {
            if (_file != null)
            {
                return(_file);
            }

            var file = _item.File;

            SPOFile.LoadFile(SPOSiteContext.CurrentSiteContext.Context, file);
            return(new SPOFile(file));
        }
コード例 #5
0
 public List <SPOFile> GetFiles()
 {
     if (!_folder.IsObjectPropertyInstantiated("Files"))
     {
         _folder.Context.Load(_folder.Files);
         _folder.Context.ExecuteQuery();
     }
     if (_files == null)
     {
         _files = new List <SPOFile>();
         foreach (File f in _folder.Files)
         {
             SPOFile.LoadFile(SPOSiteContext.CurrentSiteContext.Context, f);
             _files.Add(new SPOFile(f));
         }
         return(_files);
     }
     return(null);
 }