Пример #1
0
        public override void MapToList(ListItem dest)
        {
            Title = FileName;

            base.MapToList(dest);

            if (EventRequestId > 0)
            {
                var flv = new FieldLookupValue();
                flv.LookupId = EventRequestId;

                dest["EventRequestId"] = flv;
            }

            dest["AttachmentGuid"]   = AttachmentGuid.ToString();
            dest["TypeOfAttachment"] = TypeOfAttachment;
            dest["Size"]             = Size;
        }
Пример #2
0
        public bool Create()
        {
            bool returnVal = false;

            try
            {
                SPContext = new ClientContext(SharePointHelper.Url);

                var web  = SharePointHelper.GetWeb(SPContext);
                var list = SharePointHelper.GetList(SPContext, web, ListName);

                Folder folder = GetFolderIfExists(list, AttachmentGuid.ToString());

                if (folder == null)
                {
                    folder = CreateFolder(list, AttachmentGuid.ToString());
                }

                FileCreationInformation fci = new FileCreationInformation();

                fci.ContentStream = new MemoryStream(Content);
                fci.Url           = FileName;
                fci.Overwrite     = true;

                Microsoft.SharePoint.Client.File fileToUpload = folder.Files.Add(fci);

                MapToList(fileToUpload.ListItemAllFields);
                fileToUpload.ListItemAllFields.Update();

                SPContext.Load(fileToUpload);
                SPContext.Load(fileToUpload.ListItemAllFields);

                SPContext.ExecuteQuery();

                returnVal = true;
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to save " + ListName + " with id " + Id + ". " + ex.Message);
            }

            return(returnVal);
        }