public ActionResult Picture([FromBody] string pictureFolderName) { if (string.IsNullOrEmpty(pictureFolderName)) { return(BadRequest()); } if (_pictureRepository.IfFolderExists(pictureFolderName)) { return(BadRequest("Picture folder name already exists")); } PictureFolder pFolder = new PictureFolder() { FolderName = pictureFolderName, CreatedDate = DateTime.UtcNow, CreatedBy = "Share Point", }; _pictureRepository.Add <PictureFolder>(pFolder); _pictureRepository.Complete(); return(CreatedAtRoute("GetFolderById", new { pFolder.PictureFolderId }, _mapper.Map <PictureFolerResponse>(pFolder))); }
private void btnImportPicturesTo_Click(object sender, EventArgs e) { if (PictureFolder.ShowDialog() == DialogResult.OK) { tbImportPicsTo.Text = PictureFolder.SelectedPath; } }
public void SetPictureFolder(PictureFolder PictureFolder) { _dbContext.PictureFolder.Add(PictureFolder); }
public async void InsertData() { var oList = ClientContext.Web.Lists.GetByTitle("Partnere"); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View Scope='Recursive'><Query><ViewFields><FieldRef Name='ID'/><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef Name='CISite'/><FieldRef Name='CISiteShortUrl'/></ViewFields></Query></View>"; ListItemCollection collListItem = oList.GetItems(camlQuery); ClientContext.Load(collListItem); ClientContext.ExecuteQuery(); log.Info($"Partnere & dokumenter List data pulled successfully."); foreach (ListItem oListItem in collListItem) { try { var hyperLink = ((FieldUrlValue)(oListItem["CISite"])); log.Info($"Partner CISite Partner Id {oListItem.Id} Title :{oListItem["Title"]}"); if (hyperLink != null) { CRMPartner crmPartner = DKBSDbContext.CRMPartner.FirstOrDefault(p => p.SharePointId == int.Parse(oListItem["ID"].ToString())); if (crmPartner == null) { log.Error($"Partner not found in dkbs sql database Sharepoint Id:{oListItem.GetId()}"); continue; } log.Info($"Started Partner Id {oListItem.Id} Title :{oListItem["Title"]}"); var hLink = ((FieldUrlValue)(oListItem["CISite"])).Url; ClientContext Context = new ClientContext(hLink); Context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication; Context.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo(Configuration["SharePointUserName"], Configuration["SharePointPassword"]); Context.ExecuteQuery(); var oListData = Context.Web.Lists.GetByTitle("Billeder"); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); Context.Load(oListDataItem); Context.ExecuteQuery(); log.Info($"Pictures/Billeder List data pulled successfully. Partner Id {oListItem.GetId()}"); foreach (ListItem oItem in oListDataItem) { try { if (oItem.FileSystemObjectType == FileSystemObjectType.Folder) { Microsoft.SharePoint.Client.Folder ifolder = oItem.Folder; Context.Load(ifolder); Context.ExecuteQuery(); if (!string.IsNullOrWhiteSpace(ifolder.Name.ToLower())) { var pictureFolder = DKBSDbContext.PictureFolder.FirstOrDefault(p => p.FolderName.ToLower() == ifolder.Name.ToLower()); if (pictureFolder == null) { pictureFolder = new PictureFolder { CreatedBy = oItem.GetAuthor(), CreatedDate = oItem.GetCreateDate(), LastModifiedBy = oItem.GetEditor(), LastModified = oItem.GetModifiedDate(), FolderName = ifolder.Name }; DKBSDbContext.PictureFolder.Add(pictureFolder); DKBSDbContext.SaveChanges(); } } } if (oItem.FileSystemObjectType == FileSystemObjectType.File) { PictureFolder pictureFolder = null; Microsoft.SharePoint.Client.File lfile = oItem.File; Context.Load(lfile); Context.ExecuteQuery(); try { //get the folder var tempArray = lfile.ServerRelativeUrl.Replace(@"/" + lfile.Name, "").Split('/'); var folderName = tempArray.ToList().Last(); pictureFolder = DKBSDbContext.PictureFolder.FirstOrDefault(p => p.FolderName.ToLower() == folderName.ToLower()); if (pictureFolder == null) { log.Error($"Unable to find folder for picture. Id:{oItem["ID"]} Picture Name :{lfile.Name} Path : {lfile.ServerRelativeUrl}"); throw new ArgumentNullException($"Unable to find folder for picture. Id:{oItem.GetId()} Picture Name :{lfile.Name} Path : {lfile.ServerRelativeUrl}"); } log.Info($"Picture Name :{lfile.Name} upload started."); var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(Context, lfile.ServerRelativeUrl); await _storageService.SavePictureAsync(fileInfo.Stream, lfile.Name, crmPartner.CRMPartnerId, pictureFolder.PictureFolderId); } catch (Exception ex) { log.Error($"Unable to upload picture. Id:{oItem.GetId()} Picture Name :{lfile.Name}", ex); throw ex; } var picture = new Picture() { CreatedBy = oItem.GetAuthor(), CreatedDate = oItem.GetCreateDate(), LastModifiedBy = oItem.GetEditor(), LastModified = oItem.GetModifiedDate(), CRMPartnerId = crmPartner.CRMPartnerId, PictureFolderId = pictureFolder.PictureFolderId, PictureName = lfile.Name, Title = lfile.Title }; picture.Description = oItem["Description"].ToSharepointString(); picture.Position = oItem["ImagePosition"].ToInt(); DKBSDbContext.Picture.Add(picture); DKBSDbContext.SaveChanges(); log.Info($"Picture Name :{lfile.Name} uploaded successfully."); } } catch (Exception ex) { ErrorCount += 1; log.Error($"Unable to upload picture. Id:{oItem.GetId()}", ex); } } } } catch (Exception ex) { ErrorCount += 1; log.Error($"Partner pictures unable to load Id:{oListItem.GetId()}", ex); } } }