protected void ImportLinkButton_Click(object sender, EventArgs e) { var importDir = Path.Combine(Server.MapPath(Request.ApplicationPath), "Files"); if (Directory.Exists(importDir)) { var files = Directory.GetFiles(importDir); var errorOccurred = false; foreach (var fileName in files) { if (!fileName.ToLower().EndsWith(".config")) { var ReadWasSuccess = false; var file = new ProductFile(); file.FileName = Path.GetFileName(fileName); file.ShortDescription = file.FileName; if (HccApp.CatalogServices.ProductFiles.Create(file)) { try { using (var fileStream = new FileStream(fileName, FileMode.Open)) { if (ProductFile.SaveFile(HccApp.CurrentStore.Id, file.Bvin, file.FileName, fileStream)) { ReadWasSuccess = true; } } if (ReadWasSuccess) { File.Delete(fileName); } } catch (Exception ex) { errorOccurred = true; EventLog.LogEvent(ex); } } } } if (errorOccurred) { MessageBox1.ShowError("An error occurred during import. Please check the event log."); } else { MessageBox1.ShowOk("Files Imported Successfully."); } } else { MessageBox1.ShowInformation("Files folder doesn't exist"); } BindFileGridView(); }
protected void ImportLinkButton_Click(object sender, System.EventArgs e) { string[] files = System.IO.Directory.GetFiles(Server.MapPath(Request.ApplicationPath) + "\\Files\\"); bool errorOccurred = false; foreach (string fileName in files) { if (!fileName.ToLower().EndsWith(".config")) { bool ReadWasSuccess = false; ProductFile file = new ProductFile(); file.FileName = System.IO.Path.GetFileName(fileName); file.ShortDescription = file.FileName; if (MTApp.CatalogServices.ProductFiles.Create(file)) { try { using (System.IO.FileStream fileStream = new FileStream(fileName, FileMode.Open)) { if (ProductFile.SaveFile(MTApp.CurrentStore.Id, file.Bvin, file.FileName, fileStream)) { ReadWasSuccess = true; } } if (ReadWasSuccess == true) { File.Delete(fileName); } } catch (Exception ex) { errorOccurred = true; EventLog.LogEvent(ex); } } } } if (errorOccurred) { MessageBox1.ShowError("An error occurred during import. Please check the event log."); } else { MessageBox1.ShowOk("Files Imported Successfully."); } BindFileGridView(); }
public void DownloadOrLinkFile(ProductFile file, IMessageBox MessageBox1) { //if they browsed a file then this overrides all other behavior if (_currentMode == Mode.NewUpload) { if (file == null) { file = new ProductFile(); } InitializeProductFile(file, true); if (Save(file)) { if (ProductFile.SaveFile(HccApp.CurrentStore.Id, file.Bvin, file.FileName, NewFileUpload.PostedFile)) { MessageBox1.ShowOk("File saved to server successfully"); } else { MessageBox1.ShowError( "There was an error while trying to save your file to the file system. Please check your asp.net permissions."); } } else { MessageBox1.ShowError("There was an error while trying to save your file to the database."); } } else if (_currentMode == Mode.DropDownList) { if (!string.IsNullOrWhiteSpace(FilesDropDownList.SelectedValue)) { if (file == null) { file = new ProductFile(); } InitializeProductFile(file, true); if (Save(file)) { MessageBox1.ShowOk("File saved to server successfully"); } else { MessageBox1.ShowError("There was an error while trying to save your file to the database."); } } } else if (_currentMode == Mode.FileBrowsed) { if (file == null) { file = new ProductFile(); } InitializeProductFile(file, true); if (Save(file)) { MessageBox1.ShowOk("File saved to server successfully"); } else { MessageBox1.ShowError("There was an error while trying to save your file to the database."); } } InitializeFileLists(); }
public void DownloadOrLinkFile(ProductFile file, IMessageBox MessageBox1) { //if they browsed a file then this overrides all other behavior if (_currentMode == Mode.NewUpload) { if (file == null) { file = new ProductFile(); } InitializeProductFile(file, true); if (Save(file)) { if (ProductFile.SaveFile(HccApp.CurrentStore.Id, file.Bvin, file.FileName, NewFileUpload.PostedFile)) { MessageBox1.ShowOk(Localization.GetString("FileSaveSuccess")); } else { MessageBox1.ShowError(Localization.GetString("FileSaveFailure")); } } else { MessageBox1.ShowError(Localization.GetString("FileSaveFailure")); } } else if (_currentMode == Mode.DropDownList) { if (!string.IsNullOrWhiteSpace(FilesDropDownList.SelectedValue)) { if (file == null) { file = new ProductFile(); } InitializeProductFile(file, true); if (Save(file)) { MessageBox1.ShowOk(Localization.GetString("FileSaveSuccess")); } else { MessageBox1.ShowError(Localization.GetString("FileSaveFailure")); } } } else if (_currentMode == Mode.FileBrowsed) { if (file == null) { file = new ProductFile(); } InitializeProductFile(file, true); if (Save(file)) { MessageBox1.ShowOk(Localization.GetString("FileSaveSuccess")); } else { MessageBox1.ShowError(Localization.GetString("FileSaveFailure")); } } InitializeFileLists(); }