public Fileupload Update(Fileupload file) { var entity = db.Files.Attach(file); entity.State = Microsoft.EntityFrameworkCore.EntityState.Modified; return(file); }
public bool CreateFile(IFormFile file, CertificationsModel cert) { Fileupload img = new Fileupload(); img.FileName = file.FileName; img.Author = User.Identity.Name; img.DateAdded = DateTime.Now; img.CertificationId = cert.Id; MemoryStream ms = new MemoryStream(); file.CopyTo(ms); img.FileData = ms.ToArray(); if (fileData.DoesFileExist(img)) { return(false); } ms.Close(); ms.Dispose(); fileData.Add(img); fileData.Commit(); return(true); }
private string CreateFile(string fileName, string extension, Document Doc) { string processFilePath = string.Empty, pathToSaveDecryptedFile = string.Empty; try { string saveFile = string.Format("{0}{1}{2}{3}", Server.MapPath("FileToSave").ToString(), fileName, DateTime.Now.ToString("MMddyyyy_hhmmss"), extension); if (extension == ".xlsx") { Fileupload.SaveAs(saveFile); } else if (extension == ".pdf") { PdfWriter.GetInstance(Doc, new FileStream(saveFile, FileMode.Create)); } pathToSaveDecryptedFile = string.Format("{0}{1}{2}{3}{4}{5}", Path.GetDirectoryName(saveFile), "//", Path.GetFileNameWithoutExtension(saveFile), "_" , "Decrypt", extension); processFilePath = saveFile; } catch (Exception E) { throw E; } return(processFilePath); }
public bool DoesFileExist(Fileupload file) { var query = from data in db.Files where data.FileData == file.FileData select data; if (!query.Any()) { return(false); } return(true); }
protected void btnUpload_Click(object sender, EventArgs e) { if (Fileupload.PostedFile != null) { try { var appDataPath = Server.MapPath("~/App_Data/"); if (!Directory.Exists(appDataPath)) { Directory.CreateDirectory(appDataPath); } string path = string.Concat(appDataPath + Fileupload.FileName); Fileupload.SaveAs(path); string excelCS = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0", path); OleDbConnection con; using (con = new OleDbConnection(excelCS)) { OleDbCommand cmd = new OleDbCommand("Select * from [Sheet1$]", con); con.Open(); OleDbDataReader dr = cmd.ExecuteReader(); using (SqlConnection connection = new SqlConnection(getConnectionString())) { connection.Open(); SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(connection); //add the plant ID sqlBulkCopy.ColumnMappings.Add("Date", "Date"); sqlBulkCopy.ColumnMappings.Add("Yield", "Yield"); sqlBulkCopy.ColumnMappings.Add("Target", "Target"); sqlBulkCopy.ColumnMappings.Add("Variance", "Variance"); sqlBulkCopy.DestinationTableName = "temp_SolarProduction"; //mappings maybe sqlBulkCopy.WriteToServer(dr); AddPlantSectionID(); tranferToSolarProduction(); clearTempTable(); } } lblconfirm.Text = "Successfull Data Upload for " + plantName + "!"; } catch (Exception ex) { throw ex; //lblconfirm.Text = ex.Message; } } }
public IActionResult Details(int id) { Certification = new CertificationsModel(); Certification = CertData.GetById(id); image = new Fileupload(); image = fileData.GetByCertId(id).FirstOrDefault(); ViewBag.story = JsonConvert.SerializeObject(new String("")); if (Certification.CertUrl != null) { return(View(Certification)); } if (Certification == null) { TempData["Error"] = $"Certification does not exist"; return(RedirectToAction("Index", "Certifications")); } if (Certification.CertUrl == null && image != null) { System.Console.WriteLine("No Certification url"); string imageDataBytes = Convert.ToBase64String(image.FileData); //IF UPLOADED IS PNG if (image.FileName.Contains(".pdf")) { ViewBag.story = JsonConvert.SerializeObject(imageDataBytes); } else { string imageUrl = string.Format("data:/image/jpeg;base64,{0}", imageDataBytes); //Original Certification.CertUrl = imageUrl; } } else { TempData["Error"] = $"Certification '{Certification.CertName}' with Id: {Certification.Id} does not have a certification"; return(RedirectToAction("Index", "Certifications")); } return(View(Certification)); }
public Fileupload Add(Fileupload file) { db.Add(file); return(file); }
public void Enterpropertydetails() { _Wait.Until(ExpectedConditions.ElementExists(By.ClassName("title"))); string propdetpag = _driver.Title; Assert.AreEqual(propdetpag, "Properties | Add New Property"); Propertyname.SendKeys("NewProperty"); /* Actions actions = new Actions(_driver); * actions.MoveToElement(PropertyType); * actions.Click(); * actions.SendKeys("Section and Property"); * actions.Build().Perform();*/ StreetNo.SendKeys("1222"); IWebElement streetname = AddressElement1[0]; streetname.SendKeys("High Street"); IWebElement Suburb = AddressElement1[1]; Suburb.SendKeys("Taita"); IWebElement City = AddressElement2[1]; IWebElement Postcode = AddressElement2[2]; City.SendKeys("Lower Hutt"); Postcode.SendKeys("5011"); PropDes.SendKeys("Property Description"); Region.SendKeys("Wellington"); System.Threading.Thread.Sleep(4000); TargetRent.SendKeys("200"); Bedrooms.SendKeys("2"); YearBuilt.SendKeys("1999"); Bathrooms.SendKeys("2"); Fileupload.SendKeys(@"C:\Users\Mallik\Desktop\Test.jpg"); CarPark.SendKeys("2"); System.Threading.Thread.Sleep(1000); //File IUpload /* System.Threading.Thread.Sleep(2000); * * SendKeys.SendWait(@"C:\Users\Mallik\Desktop\Test.jpg"); * System.Threading.Thread.Sleep(2000); * * SendKeys.SendWait(@"{Enter}"); */ YearBuilt.Click(); System.Threading.Thread.Sleep(1000); ClickNext.Click(); }
public string Upload() { /* PURPOSE: allow display images upload for anything that has only 1 display image * * RETURNS: database value for imagepath * - IE: Assets/Images/Projects/[username]/[ProjectName]/[ImageNameAndExt] * * OTHER INFO: * - This will not work with screenshots * - This will delete any images with the same name located in the same location because: * + A Project can only have 1 Display Image * + A Portfolio can only have 1 Display Image * + A Profile can only have 1 Display Image * * PARAMETERS FROM OBJECT: * - UserName = The Username of the user uploading image * - FilePath = Objects Current Image Path as saved in database * - FileUpload = The File attempting to uploaded by a User * - ObjectType = The type of object its uploading for (Project, Portfolio, Profile) * - ProjectName = The Name of the Object type * + IE: if ObjectType=Project then ProjectName=[NAME OF PROJECT] * + IE: if ObjectType=Portfolio then then ProjectName=[NAME OF PORTFOLIO] * + IE: if ObjectType=Profile then ProjectName will be set to "DisplayImage" */ try { string SavePath = ""; //Upload Zip Logic string fileName = ""; //Default Zip FilePath for Project string DefaultFilePath = "Assets/Zipfiles/" + UserName; string DefaultFileName = "Default"; string absolutepath = ""; //Empty FilePath Check if (FilePath == string.Empty || FilePath == null) { //Set empty filepath to Default zip SavePath = "Assets/Zipfiles/" + UserName; fileName = DefaultFileName; FilePath = SavePath + "/" + fileName; } //Null file upload check if (Fileupload != null) { fileName = Path.GetFileName(Fileupload.FileName); var fullPath = HttpContext.Current.Server.MapPath("~/" + FilePath); // Check if existing filepath exists on server if (File.Exists(fullPath)) { // Current fullPath of Project Exists Logic } else { // Set FilePath to default FilePath = DefaultFilePath; } // Check for Existing Directory on server if (Directory.Exists("~/Zipfiles/" + UserName)) { // Project Folder exists Logic } else { // Create Project Folder Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Zipfiles/" + UserName)); } SavePath = "Assets/Zipfiles/" + UserName; // Check if UserName folder existings in Project folder if (Directory.Exists("~/Assets/Zipfiles/" + UserName + "/" + "Projects")) { // UserName folder in Project folder Exists Logic } else { /* * Project folder in UserName folder DOESN'T Exist * - Create Project Folder in UserName folder */ Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Assets/Zipfiles/" + UserName + "/" + "Projects")); } SavePath = "Assets/Zipfiles/" + "Projects" + "/" + UserName; // Check if ProjectName folder existings in UserName folder if (Directory.Exists("~/Assets/Zipfiles/" + UserName + "/" + "Projects" + "/" + ProjectName)) { // ProjectName folder in ObjectType folder Exists Logic } else { /* * ProjectName folder in ObjectType folder DOESNT Exists * - Create ProjectName Folder in UserName folder */ Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Assets/Zipfiles/" + UserName + "/" + "Projects" + "/" + ProjectName)); } SavePath = "Assets/Zipfiles/" + UserName + "/" + "Projects" + "/" + ProjectName; fullPath = HttpContext.Current.Server.MapPath("~/" + SavePath + "/" + fileName); // If File with same name exists delete it if (File.Exists(fullPath)) { File.Delete(fullPath); } absolutepath = SavePath + "/" + fileName; } else { // FileUpload is null absolutepath = FilePath; } // Upload new file to server if not null if (Fileupload != null) { Fileupload.SaveAs(HttpContext.Current.Server.MapPath("~/" + absolutepath)); return(absolutepath); } else { return(null); } } catch (Exception ex) { throw ex; } }