public List <PersonFiles> SaveSplitDocument(Stream document) { List <PersonFiles> resultList = new List <PersonFiles>(); byte[] byteArray = StreamTools.ReadFully(document); using (MemoryStream documentInMemoryStream = new MemoryStream(byteArray, 0, byteArray.Length, true, true)) { foreach (OpenXMLDocumentPart <Sheet> element in DocumentElements) { OpenXmlPowerToolsDocument docDividedPowerTools = new OpenXmlPowerToolsDocument(DocumentName, documentInMemoryStream); using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(docDividedPowerTools)) { SpreadsheetDocument excelDoc = streamDoc.GetSpreadsheetDocument(); excelDoc.WorkbookPart.Workbook.Sheets.RemoveAllChildren(); Sheets sheets = excelDoc.WorkbookPart.Workbook.Sheets; foreach (Sheet compo in element.CompositeElements) { sheets.Append(compo.CloneNode(false)); } excelDoc.WorkbookPart.Workbook.Save(); var person = new PersonFiles(); person.Person = element.PartOwner; resultList.Add(person); person.Name = element.Guid.ToString(); person.Data = streamDoc.GetModifiedDocument().DocumentByteArray; } } OpenXmlPowerToolsDocument docPowerTools = new OpenXmlPowerToolsDocument(DocumentName, documentInMemoryStream); using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(docPowerTools)) { SpreadsheetDocument excelDoc = streamDoc.GetSpreadsheetDocument(); excelDoc.WorkbookPart.Workbook.Sheets.RemoveAllChildren(); excelDoc.WorkbookPart.Workbook.Save(); var person = new PersonFiles(); person.Person = "/"; resultList.Add(person); person.Name = "template.xlsx"; person.Data = streamDoc.GetModifiedDocument().DocumentByteArray; } } var xmlPerson = new PersonFiles(); xmlPerson.Person = "/"; resultList.Add(xmlPerson); xmlPerson.Name = "mergeXmlDefinition.xml"; xmlPerson.Data = CreateMergeXml(); return(resultList); }
public List <PersonFiles> SaveSplitDocument(Stream document) { List <PersonFiles> resultList = new List <PersonFiles>(); byte[] byteArray = StreamTools.ReadFully(document); using (MemoryStream documentInMemoryStream = new MemoryStream(byteArray, 0, byteArray.Length, true, true)) { OpenXmlPowerToolsDocument docPowerTools = new OpenXmlPowerToolsDocument(DocumentName, documentInMemoryStream); using (OpenXmlMemoryStreamDocument streamTemplateDoc = new OpenXmlMemoryStreamDocument(docPowerTools)) { PresentationDocument templatePresentation = streamTemplateDoc.GetPresentationDocument(); foreach (OpenXMLDocumentPart <SlideId> element in DocumentElements) { OpenXmlPowerToolsDocument emptyDocPowerTools = new OpenXmlPowerToolsDocument(DocumentName, documentInMemoryStream); using (OpenXmlMemoryStreamDocument streamDividedDoc = new OpenXmlMemoryStreamDocument(emptyDocPowerTools)) { var relationshipIds = element.CompositeElements.Select(c => c.RelationshipId.Value).ToList(); PresentationDocument dividedPresentation = streamDividedDoc.GetPresentationDocument(); PresentationTools.InsertSlidesFromTemplate(PresentationTools.RemoveAllSlides(dividedPresentation), templatePresentation, relationshipIds); var person = new PersonFiles(); person.Person = element.PartOwner; resultList.Add(person); person.Name = element.Guid.ToString(); person.Data = streamDividedDoc.GetModifiedDocument().DocumentByteArray; } } } using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(docPowerTools)) { PresentationDocument preDoc = streamDoc.GetPresentationDocument(); PresentationTools.RemoveAllSlides(preDoc); var person = new PersonFiles(); person.Person = "/"; resultList.Add(person); person.Name = "template.pptx"; person.Data = streamDoc.GetModifiedDocument().DocumentByteArray; } var xmlPerson = new PersonFiles(); xmlPerson.Person = "/"; resultList.Add(xmlPerson); xmlPerson.Name = "mergeXmlDefinition.xml"; xmlPerson.Data = CreateMergeXml(); } return(resultList); }
//public ActionResult SelfBars(string Id, string userType) //{ // //PersonBars personBars = new PersonBars(); // //personBars.Id = Id; personBars.userType = userType; // //personBars.pbars = ContextManger.Database.SqlQuery<BarDetail>("Select * from V_Bars_Users vb where vb.ToUID is null and vb.PBID=vb.FBID and vb.FBID = '0'") // // .Where(m=>m.FromId==Id).OrderBy(m=>m.RaiseQuesTime).ToList(); // ////personBars.fbars = ContextManger.Database.SqlQuery<BarDetail>("Select * from V_Bars_Users vb where vb.PBID=vb.FBID and vb.FBID <> '0'").ToList(); // ////personBars.sbars = ContextManger.Database.SqlQuery<BarDetail>("Select * from V_Bars_Users vb where vb.PBID <>vb.FBID").ToList(); // //personBars.counts = count(Id, userType); // //return View(personBars); //} public ActionResult SelfFiles(string Id, string userType) { PersonFiles fileD = new PersonFiles(); fileD.Id = Id; fileD.userType = userType; fileD.sfile = ContextManger.File.Where(m => m.FromUID == Id).ToList(); fileD.downup = ContextManger.DownUpload.ToList().Select(m => new DownUpDetail() { DID = m.DID, Time = m.Time, ToId = m.ToUID, FID = m.FID, Readstate = m.Readstate, ToUID = UserManager.FindById(m.ToUID).RealName }).ToList(); fileD.counts = count(Id, userType); return(View(fileD)); }
/// <summary> /// პიროვნების ფაილის ატვირთვა რედაქტირება /// </summary> /// <param name="personId"></param> /// <param name="filesData"></param> /// <returns></returns> public async Task <Result> UploadUpdatePersonFile(int?personId, IFormFileCollection pFiles) { var currentDate = DateTime.Now; if (personId == 0 || personId == null) { return(new Result(false, 12, ValidationMassages.PersonIdMustProvided)); } if (pFiles.IsNullOrEmpty()) { return(new Result(false, 13, ValidationMassages.FileMustProvided)); } var filesData = pFiles.First(); // არსებობს თუ არა ასეთი იდენტიფიქატორით ჩანაწერი var personDB = await personRepository.GetParentPersonAsync(personId.GetValueOrDefault()); if (personDB == null) { return(new Result(false, 13, ValidationMassages.PersonNotFound)); } //ფაილის ფორმატზე გადამოწმება var fileType = Path.GetExtension(filesData.FileName).ToLower(); if (!fileFormat.Contains(fileType, StringComparison.OrdinalIgnoreCase)) { return(new Result(false, -1, ValidationMassages.WrongFileFormat)); } //var megabyte = new decimal(1024 * 1024); //// ფაილის ზომის წამოღება //var uploadFileSize = Math.Round(filesData.Length / megabyte, 2, MidpointRounding.AwayFromZero); //if ((uploadFileSize) > 5) //{ // return new Result(false, -1, "ფაილების მაქსიმალური ზომა არ უნდა აღემატებოდეს 5MB -ს"); //} //ფაილებს ვინახავთ პიროვნების იდენტიფიქატორის სახელის მქონე საქაღალდეში var subDirectory = personId.GetValueOrDefault().ToString(); var target = Path.Combine(directoryAddress, subDirectory); // თუ ესეთი საქაღალდე არ არსებობს if (!Directory.Exists(target)) { Directory.CreateDirectory(target); } //ფაილის შენახვა მოცემულ საქაღალდეში var filePath = Path.Combine(target, Guid.NewGuid().ToString() + fileType); using (var stream = new FileStream(filePath, FileMode.Create)) { await filesData.CopyToAsync(stream); } var personFiles = new PersonFiles { FilePath = filePath, PersonId = personId.GetValueOrDefault(), DateCreated = currentDate, }; var result = await personFilesRepository.UpdatePersonFilesAsync(personFiles); return(result); }
public List <PersonFiles> SaveSplitDocument(Stream document) { List <PersonFiles> resultList = new List <PersonFiles>(); byte[] byteArray = StreamTools.ReadFully(document); using (MemoryStream documentInMemoryStream = new MemoryStream(byteArray, 0, byteArray.Length, true, true)) { foreach (OpenXMLDocumentPart <OpenXmlElement> element in DocumentElements) { OpenXmlPowerToolsDocument docDividedPowerTools = new OpenXmlPowerToolsDocument(DocumentName, documentInMemoryStream); using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(docDividedPowerTools)) { WordprocessingDocument wordDoc = streamDoc.GetWordprocessingDocument(); wordDoc.MainDocumentPart.Document.Body.RemoveAllChildren(); Body body = wordDoc.MainDocumentPart.Document.Body; foreach (OpenXmlElement compo in element.CompositeElements) { body.Append(compo.CloneNode(true)); } wordDoc.MainDocumentPart.Document.Save(); var person = new PersonFiles(); person.Person = element.PartOwner; resultList.Add(person); person.Name = element.Guid.ToString(); person.Data = streamDoc.GetModifiedDocument().DocumentByteArray; } } // At this point, the memory stream contains the modified document. // We could write it back to a SharePoint document library or serve // it from a web server. OpenXmlPowerToolsDocument docPowerTools = new OpenXmlPowerToolsDocument(DocumentName, documentInMemoryStream); using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(docPowerTools)) { WordprocessingDocument wordDoc = streamDoc.GetWordprocessingDocument(); wordDoc.MainDocumentPart.Document.Body.RemoveAllChildren(); wordDoc.MainDocumentPart.Document.Save(); var person = new PersonFiles(); person.Person = "/"; resultList.Add(person); person.Name = "template.docx"; person.Data = streamDoc.GetModifiedDocument().DocumentByteArray; } } // At this point, the memory stream contains the modified document. // We could write it back to a SharePoint document library or serve // it from a web server. var xmlPerson = new PersonFiles(); xmlPerson.Person = "/"; resultList.Add(xmlPerson); xmlPerson.Name = "mergeXmlDefinition.xml"; xmlPerson.Data = CreateMergeXml(); return(resultList); }