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));
        }
        public SPOFile GetFile(string fileName)
        {
            var file = _folder.Files.GetByUrl(fileName);

            SPOFile.LoadFile(SPOSiteContext.CurrentSiteContext.Context, file);
            return(new SPOFile(file));
        }
        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));
        }
Exemple #4
0
        public SPOFile GetFile()
        {
            if (_file != null)
            {
                return(_file);
            }

            var file = _item.File;

            SPOFile.LoadFile(SPOSiteContext.CurrentSiteContext.Context, file);
            return(new SPOFile(file));
        }
 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);
 }
 public SPOFile GetFileByServerRelativeUrl(string serverRelativeUrl)
 {
     var file = _web.GetFileByServerRelativeUrl(serverRelativeUrl);
     SPOFile.LoadFile(SPOSiteContext.CurrentSiteContext.Context, file);
     var spoFile = new SPOFile(file);
     if (spoFile.ListItemAllFields != null && (spoFile.ListItemAllFields.FieldValues.ContainsKey("WikiField") ||
         (serverRelativeUrl.ToLower().Contains("/sitepages/") && serverRelativeUrl.ToLower().Contains(".aspx"))))
         return new SPOWikiPage(file);
     return spoFile;
 }
 public SPOFilePipeBind(SPOFile file)
 {
     _serverRelativeUrl = file.ServerRelativeUrl;
 }