private void btnSubmit_Click(object sender, EventArgs e) { using (NetworkShareAccesser.Access("PLGUNV_NAS", @"", "pitd.is_user", "Apple_01")) { StaticSettings staticSettings = new StaticSettings(); UnitOfWork unitOfWork = new UnitOfWork(); var root = $@"\\plgunv_nas\is_docs\ofmis\{staticSettings.Offices.OffcAcr}"; if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } var fileName = Guid.NewGuid().ToString(); var path = Path.Combine(root, fileName + ".png"); pctScanImage.Image.Save(path, ImageFormat.Png); unitOfWork.FilesRepo.Insert(new Models.Files() { RefId = scanners.RefId, TableName = "Action", RootFolder = root, Path = fileName, }); unitOfWork.Save(); Close(); } }
public virtual void btnDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("Do you want to Delete this?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } using (NetworkShareAccesser.Access("PLGUNV_NAS", @"", "pitd.is_user", "Apple_01")) { StaticSettings staticSettings = new StaticSettings(); UnitOfWork unitOfWork = new UnitOfWork(); var root = $@"\\plgunv_nas\is_docs\ofmis\{staticSettings.Offices.OffcAcr}"; if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } var files = unitOfWork.FilesRepo.Find(x => x.RefId == documentActions.Id && x.TableName == "Action"); var path = Path.Combine(root, files.Path + ".png"); File.Delete(path); unitOfWork.FilesRepo.Delete(x => x.Id == files.Id); unitOfWork.Save(); Detail(); } }
private void dtgv_DocsN2_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (ACSConfig.GetNetworkAccesser().Valid) { try { using (var nsa = NetworkShareAccesser.Access(ACSConfig.GetStorage().Output, ACSConfig.GetNetworkAccesser().Domain, ACSConfig.GetNetworkAccesser().User, ACSConfig.GetNetworkAccesser().Password)) { getPictureInGrid(e, senderGrid); } } catch (Exception g) { ACSLog.InsertLog(MessageBoxIcon.Error, g); WFMessageBox.Show(g.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { getPictureInGrid(e, senderGrid); } }
private void btnFileView_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (DocumentGrid.GetFocusedRow() is Documents documents) { using (NetworkShareAccesser.Access("PLGUNV_ADSERVER", @"PLGUNV", "administrator", "itpower@123")) { try { XtraForm xtraForm = new XtraForm() { StartPosition = FormStartPosition.CenterScreen }; var pct = new PictureEdit() { Dock = DockStyle.Fill, Image = Image.FromFile(Path.Combine(documents.RootDirectory, documents.FileId + documents.ExtName)), }; pct.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Squeeze; xtraForm.Controls.Add(pct); xtraForm.ShowDialog(); } catch (Exception exception) { MessageBox.Show(exception.Message, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } }
public override TaskStatus Run() { Info("Moving directory..."); var success = false; try { if (!string.IsNullOrEmpty(SmbComputerName) && !string.IsNullOrEmpty(SmbUsername) && !string.IsNullOrEmpty(SmbPassword)) { using (NetworkShareAccesser.Access(SmbComputerName, SmbDomain, SmbUsername, SmbPassword)) { success = MoveDirectory(); } } else { success = MoveDirectory(); } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while moving folder.", e); success = false; } Info("Task finished."); return(new TaskStatus(success ? Status.Success : Status.Error, false)); }
protected void LinkBtnComputer_Click(object sender, EventArgs e) { string servername = ConfigurationManager.AppSettings["ServerName"].ToString(); string domainame = ConfigurationManager.AppSettings["DomainName"].ToString(); string username = ConfigurationManager.AppSettings["UserName"].ToString(); string password = ConfigurationManager.AppSettings["Password"].ToString(); string folderpath; using (NetworkShareAccesser.Access(servername, domainame, username, password)) { folderpath = ConfigurationManager.AppSettings["DocumentsPath"].ToString(); string[] files = Directory.GetFiles(folderpath); string filename1 = "Computer Science.xlsx"; string path_BoxId = Path.Combine(folderpath, filename1); string newpath = path_BoxId.Replace('\\', '/'); string filePath = path_BoxId; var uri = new Uri(newpath); string filename = Path.GetFullPath(uri.LocalPath); HttpResponse response = HttpContext.Current.Response; response.Clear(); response.ClearContent(); response.ClearHeaders(); response.Buffer = false; WebClient wc = new WebClient(); response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", Path.GetFileName(newpath))); response.ContentType = "application/octet-stream"; byte[] data = wc.DownloadData(filePath); response.BinaryWrite(data); response.End(); } }
public override TaskStatus Run() { Info("Renaming files..."); var success = true; var atLeastOneSucceed = false; if (!string.IsNullOrEmpty(SmbComputerName) && !string.IsNullOrEmpty(SmbUsername) && !string.IsNullOrEmpty(SmbPassword)) { using (NetworkShareAccesser.Access(SmbComputerName, SmbDomain, SmbUsername, SmbPassword)) { success = RenameFiles(ref atLeastOneSucceed); } } else { success = RenameFiles(ref atLeastOneSucceed); } var status = Status.Success; if (!success && atLeastOneSucceed) { status = Status.Warning; } else if (!success) { status = Status.Error; } Info("Task finished."); return(new TaskStatus(status, false)); }
protected void ViewPDF(Object sender, EventArgs e) { LinkButton lb = (LinkButton)sender; GridViewRow row = (GridViewRow)lb.NamingContainer; int index = row.RowIndex; //gets the row index selected var lblPubID = row.FindControl("lblPubID") as Label; string id = lblPubID.Text; string servername = ConfigurationManager.AppSettings["ServerName"].ToString(); string domainame = ConfigurationManager.AppSettings["DomainName"].ToString(); string username = ConfigurationManager.AppSettings["UserName"].ToString(); string password = ConfigurationManager.AppSettings["Password"].ToString(); string folderpath; string path_BoxId; using (NetworkShareAccesser.Access(servername, domainame, username, password)) { folderpath = ConfigurationManager.AppSettings["FolderPath"].ToString(); path_BoxId = Path.Combine(folderpath, id); int id1 = popupStudentGrid.SelectedIndex; Label filepath = (Label)popupStudentGrid.Rows[index].FindControl("lblgetid"); string path = filepath.Text; //actual filelocation path string newpath = path.Replace('\\', '/'); // replacing '\' by '/' to view image or pdf Session["path"] = newpath; Response.Write("<script>"); Response.Write("window.open('DisplayPdf.aspx?val=" + newpath + "','_blank')"); //Response.Redirect("DisplayPdf.aspx?val=" + newpath + "','_blank')"); Response.Write("</script>"); } }
public override TaskStatus Run() { Info("Checking..."); TaskStatus ts; try { if (!string.IsNullOrEmpty(SmbComputerName) && !string.IsNullOrEmpty(SmbUsername) && !string.IsNullOrEmpty(SmbPassword)) { using (NetworkShareAccesser.Access(SmbComputerName, SmbDomain, SmbUsername, SmbPassword)) { CheckFiles(); } } else { CheckFiles(); } ts = new TaskStatus(Status.Success); } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while checking the files: {0}", e.Message); ts = new TaskStatus(Status.Error); } Info("Task finished."); return(ts); }
private void btnPreviewRepo_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (DocActionGridView.GetFocusedRow() is DocumentActions item) { using (NetworkShareAccesser.Access("PLGUNV_NAS", @"", "pitd.is_user", "Apple_01")) { StaticSettings staticSettings = new StaticSettings(); UnitOfWork unitOfWork = new UnitOfWork(); var root = $@"\\plgunv_nas\is_docs\ofmis\{staticSettings.Offices.OffcAcr}"; if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } var files = unitOfWork.FilesRepo.Find(x => x.RefId == item.Id && x.TableName == "Action"); if (files == null) { return; } var path = Path.Combine(root, files.Path + ".png"); frmPreviewer frm = new frmPreviewer(path); frm.ShowDialog(); } } }
private void fnBtnAssinar() { btnCoAssinador.Enabled = false; lblInformativo.Text = "Trabalhando em sua requisição..."; if (ACSConfig.GetNetworkAccesser().Valid) { try { using (var nsa = NetworkShareAccesser.Access(ACSConfig.GetStorage().Output, ACSConfig.GetNetworkAccesser().Domain, ACSConfig.GetNetworkAccesser().User, ACSConfig.GetNetworkAccesser().Password)) { fnCoassinar(); } } catch (Exception g) { ACSLog.InsertLog(MessageBoxIcon.Error, g); WFMessageBox.Show(g.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); btnCoAssinador.Enabled = true; } } else { fnCoassinar(); } }
private void btnGetData_Click(object sender, EventArgs e) { try { if (InventoryAgentPath.Length > 0) { // create inventory agent directory LocalPath = Destination + @"\Snow Inventory Agent\" + txtDeviceName.Text + @"\"; if (Directory.Exists(LocalPath) == false) { Directory.CreateDirectory(LocalPath); } if (cbUseCredentials.Checked) { using (NetworkShareAccesser.Access(txtDeviceName.Text, txtUsername.Text, txtPassword.Text)) { NetworkFileCopier(); } } else { NetworkFileCopier(); } } else { MessageBox.Show("Inventory path is null", "Inventory Path", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Uncaught Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnFileDownload_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (DocumentGrid.GetFocusedRow() is Documents documents) { SaveFileDialog dialog = new SaveFileDialog() { OverwritePrompt = true, AddExtension = true, DefaultExt = documents.ExtName.Replace(".", "") }; if (dialog.ShowDialog() == DialogResult.OK) { using (NetworkShareAccesser.Access("PLGUNV_ADSERVER", @"PLGUNV", "administrator", "itpower@123")) { try { File.Copy(Path.Combine(documents.RootDirectory, documents.FileId + documents.ExtName), dialog.FileName); } catch (Exception exception) { MessageBox.Show(exception.Message, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } }
private void button2_Click(object sender, EventArgs e) { using (NetworkShareAccesser.Access(GetFQDN(), IPAddressCheck(), "*****@*****.**", "971364825135win8")) { File.Copy("\\\\" + label1.Text + "\\TestFolder\\" + fPath.getNama + "", @"D:\movie\" + fPath.getNama + "", true); } }
public override TaskStatus Run() { InfoFormat("Watching the folder {0} ...", FolderToWatch); try { if (!string.IsNullOrEmpty(SmbComputerName) && !string.IsNullOrEmpty(SmbUsername) && !string.IsNullOrEmpty(SmbPassword)) { using (NetworkShareAccesser.Access(SmbComputerName, SmbDomain, SmbUsername, SmbPassword)) { if (!Directory.Exists(FolderToWatch)) { ErrorFormat("The folder {0} does not exist.", FolderToWatch); return(new TaskStatus(Status.Error)); } InitFileSystemWatcher(); } } else { if (!Directory.Exists(FolderToWatch)) { ErrorFormat("The folder {0} does not exist.", FolderToWatch); return(new TaskStatus(Status.Error)); } InitFileSystemWatcher(); } } catch (ThreadAbortException) { if (Watcher != null) { Watcher.EnableRaisingEvents = false; Watcher.Dispose(); } throw; } catch (Exception e) { if (Watcher != null) { Watcher.EnableRaisingEvents = false; Watcher.Dispose(); } ErrorFormat("An error occured while initializing FileSystemWatcher.", e); } Info("Task finished"); return(new TaskStatus(Status.Success)); }
private void btnTestFileServer_Click(object sender, EventArgs e) { using (NetworkShareAccesser.Access("PLGUNV_NAS", @"", "pitd.is_user", "Apple_01")) { StaticSettings staticSettings = new StaticSettings(); var path = $@"\\plgunv_nas\is_docs\ofmis\{staticSettings.Offices.OffcAcr}"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } File.Create(Path.Combine(path, "txt.txt")); } }
private bool portparacheck(Label lb, TextBox tb, int Portindex) { bool flag = false; Ecovalidate.checkTextIsNull(tb, ref flag); if (flag) { EcoMessageBox.ShowError(EcoLanguage.getMsg(LangRes.Required, new string[] { lb.Text })); return(false); } if (!Ecovalidate.Rangeint(tb, 1, 65535)) { EcoMessageBox.ShowError(EcoLanguage.getMsg(LangRes.Range, new string[] { lb.Text, "1", "65535" })); return(false); } int port = System.Convert.ToInt32(tb.Text); bool flag2 = false; switch (Portindex) { case 0: case 2: case 3: flag2 = NetworkShareAccesser.TcpPortInUse(port); break; case 1: flag2 = NetworkShareAccesser.UDPPortInUse(port); break; } if (flag2) { tb.Focus(); EcoMessageBox.ShowError(EcoLanguage.getMsg(LangRes.Portconflict, new string[] { tb.Text })); return(false); } return(true); }
public override TaskStatus Run() { Info("Converting CSV files to JSON files..."); var success = true; var atLeastOneSuccess = false; try { if (!string.IsNullOrEmpty(SmbComputerName) && !string.IsNullOrEmpty(SmbUsername) && !string.IsNullOrEmpty(SmbPassword)) { using (NetworkShareAccesser.Access(SmbComputerName, SmbDomain, SmbUsername, SmbPassword)) { success = ConvertFiles(ref atLeastOneSuccess); } } else { success = ConvertFiles(ref atLeastOneSuccess); } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while converting files.", e); success = false; } var status = Status.Success; if (!success && atLeastOneSuccess) { status = Status.Warning; } else if (!success) { status = Status.Error; } Info("Task finished."); return(new TaskStatus(status)); }
public override TaskStatus Run() { Info("Checking file..."); var success = false; try { try { if (!string.IsNullOrEmpty(SmbComputerName) && !string.IsNullOrEmpty(SmbUsername) && !string.IsNullOrEmpty(SmbPassword)) { using (NetworkShareAccesser.Access(SmbComputerName, SmbDomain, SmbUsername, SmbPassword)) { success = CheckFile(); } } else { success = CheckFile(); } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while checking the file.", e); success = false; } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while checking file {0}. Error: {1}", File, e.Message); return(new TaskStatus(Status.Error, false)); } Info("Task finished"); return(new TaskStatus(Status.Success, success)); }
private void ScanFile() { if (!Directory.Exists("Temp")) { Directory.CreateDirectory("Temp"); } else { DirectoryInfo dirInfo = new DirectoryInfo("Temp"); foreach (FileInfo file in dirInfo.GetFiles()) { file.Delete(); } } var network = new NetworkShareAccesser(); _load.SetLabel("Проверка доступности локального сервера"); network.SaveACopy(@"\\S1\Alldoc\Install\Программы\Обновления\Одиноко проживающие\", Path.Combine(Application.StartupPath, "Temp"), 1500); Thread.Sleep(2500); DirectoryInfo di = new DirectoryInfo(Path.Combine(Application.StartupPath, "Temp")); FileInfo[] files = di.GetFiles(); if (files.Length != 0) { UpdateProgram(); } else { try { FTPConnect(); UpdateProgram(); } catch (Exception ex) { MessageBox.Show( @"Произошла ошибка при обновлении. Обратитесь к разработчику.", @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); new Configuration().ShowDialog(); var commandClient = new CommandClient(); commandClient.WriteFileError(ex, "Обновление"); } } }
private void btnSMBBrowse_Click(object sender, System.EventArgs e) { string text = this.tbSMBUsername.Text; string text2 = this.tbSMBPsw.Text; if (text.Length > 0) { string arg_31_0 = this.tbSMBDir.Text; bool flag = false; Ecovalidate.checkTextIsNull(this.tbSMBDir, ref flag); if (flag) { EcoMessageBox.ShowError(EcoLanguage.getMsg(LangRes.Required, new string[] { this.lbSMBDir.Text })); return; } string text3 = this.tbSMBDir.Text; string text4 = text3; while (text4.StartsWith("\\")) { text4 = text4.Substring(1); } int num = text4.IndexOf('\\'); if (num > 0) { text4 = text4.Substring(0, num); } NetworkShareAccesser networkShareAccesser = NetworkShareAccesser.Access(text4, text, text2); if (networkShareAccesser.Result.Length > 0) { EcoMessageBox.ShowError(EcoLanguage.getMsg(LangRes.Task_Connectfailed, new string[0])); return; } } FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); folderBrowserDialog.SelectedPath = this.tbSMBDir.Text; if (folderBrowserDialog.ShowDialog() == DialogResult.OK) { this.tbSMBDir.Text = folderBrowserDialog.SelectedPath; } }
public override TaskStatus Run() { Info("Generating MediaInfo informations..."); try { if (!string.IsNullOrEmpty(SmbComputerName) && !string.IsNullOrEmpty(SmbUsername) && !string.IsNullOrEmpty(SmbPassword)) { using (NetworkShareAccesser.Access(SmbComputerName, SmbDomain, SmbUsername, SmbPassword)) { InformFiles(); } } else { InformFiles(); } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while generating MediaInfo information.", e); _success = false; } var status = Core.Status.Success; if (!_success && _atLeastOneSucceed) { status = Core.Status.Warning; } else if (!_success) { status = Core.Status.Error; } Info("Task finished."); return(new TaskStatus(status)); }
public override TaskStatus Run() { Info("Checking..."); bool success = true; try { if (!string.IsNullOrEmpty(SmbComputerName) && !string.IsNullOrEmpty(SmbUsername) && !string.IsNullOrEmpty(SmbPassword)) { using (NetworkShareAccesser.Access(SmbComputerName, SmbDomain, SmbUsername, SmbPassword)) { CheckFiles(); } } else { CheckFiles(); } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while checking files and folders. Error: {0}", e.Message); success = false; } var status = Status.Success; if (!success) { status = Status.Error; } Info("Task finished."); return(new TaskStatus(status, false)); }
protected void GVViewUploadedRecordsView_SelectedIndexChanged(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "VIEW") { GridViewRow rowSelect = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer); int rowindex = rowSelect.RowIndex; string servername = ConfigurationManager.AppSettings["ServerName"].ToString(); string domainame = ConfigurationManager.AppSettings["DomainName"].ToString(); string username = ConfigurationManager.AppSettings["UserName"].ToString(); string password = ConfigurationManager.AppSettings["Password"].ToString(); string mainpath = ConfigurationManager.AppSettings["UploadUserPath"].ToString(); using (NetworkShareAccesser.Access(servername, domainame, username, password)) { int id = GridView1.SelectedIndex; System.Web.UI.WebControls.Label filepath = (System.Web.UI.WebControls.Label)GridView1.Rows[rowindex].FindControl("FilePath"); string path = filepath.Text; //actual filelocation path string newpath = path.Replace('\\', '/'); // replacing '\' by '/' to view image or pdf string extention = Path.GetExtension(newpath); int len = extention.Length - 1; string extwithoutdot = extention.Substring(1, len); string filetype = ""; FileInfo myfile = new FileInfo(path); if (myfile.Exists) { HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + newpath); HttpContext.Current.Response.AddHeader("Content-Length", myfile.Length.ToString()); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.TransmitFile(myfile.FullName); HttpContext.Current.Response.End(); } } } }
public override TaskStatus Run() { Info("Zipping files..."); var success = true; try { if (!string.IsNullOrEmpty(SmbComputerName) && !string.IsNullOrEmpty(SmbUsername) && !string.IsNullOrEmpty(SmbPassword)) { using (NetworkShareAccesser.Access(SmbComputerName, SmbDomain, SmbUsername, SmbPassword)) { success = CreateZip(); } } else { success = CreateZip(); } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while creating 7z.", e); success = false; } var status = Status.Success; if (!success) { status = Status.Error; } Info("Task finished."); return(new TaskStatus(status)); }
public override TaskStatus Run() { Info("Checking folder..."); var success = false; TaskStatus status = null; try { if (!string.IsNullOrEmpty(SmbComputerName) && !string.IsNullOrEmpty(SmbUsername) && !string.IsNullOrEmpty(SmbPassword)) { using (NetworkShareAccesser.Access(SmbComputerName, SmbDomain, SmbUsername, SmbPassword)) { success = CheckFolder(ref status); } } else { success = CheckFolder(ref status); } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while checking the folder.", e); success = false; } Info("Task finished"); if (status != null) { return(status); } return(new TaskStatus(Status.Success, success)); }
private void btnSubmit_Click(object sender, EventArgs e) { try { Scanners.ImageId = Guid.NewGuid().ToString(); var updatePath = @"\\PLGUNV_ADSERVER\c$\Installers\Profiling\Profiling_Data\Scanned Documents"; //NetworkCredential theNetworkCredential = new NetworkCredential("administrator", "Itpower@123"); //CredentialCache theNetcache = new CredentialCache(); //theNetcache.Add(new Uri(updatePath), "Basic", theNetworkCredential); using (NetworkShareAccesser.Access("PLGUNV_ADSERVER", @"PLGUNV", "administrator", "itpower@123")) { this.pictureEdit1.Image.Save(Path.Combine(updatePath, Scanners.ImageId + ".png")); } using (UnitOfWork unitOfWork = new UnitOfWork()) { unitOfWork.DocumentsRepo.Insert(new Models.Documents() { FileId = Scanners.ImageId, ExtName = ".png", RootDirectory = updatePath, TableName = Scanners.TableName, RefId = Scanners.RefId, CreatedBy = User.UserId, FileSize = new FileInfo(Path.Combine(updatePath, Scanners.ImageId + ".png")).Length, DocumentDescription = memoExEdit1.Text, DateCreated = DateTime.Now }); unitOfWork.Save(); } } catch (Exception exception) { MessageBox.Show(exception.Message, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Close(); }
private void GetFileCount() { // null out the counters LogCount = 0; SnowpackCount = 0; if (cbUseCredentials.Checked) { using (NetworkShareAccesser.Access(txtDeviceName.Text, txtUsername.Text, txtPassword.Text)) { foreach (var i in Directory.GetFiles(Inventory.ConvertDirectory(InventoryAgentPath, txtDeviceName.Text) + @"\data\").Select(x => new FileInfo(x)).OrderByDescending(x => x.LastWriteTime).ToArray()) { if (i.Extension.ToLower().Contains("log")) { LogCount += 1; } else if (i.Extension.ToLower().Contains("snowpack")) { SnowpackCount += 1; } } } } else { foreach (var i in Directory.GetFiles(Inventory.ConvertDirectory(InventoryAgentPath, txtDeviceName.Text) + @"\data\").Select(x => new FileInfo(x)).OrderByDescending(x => x.LastWriteTime).ToArray()) { if (i.Extension.ToLower().Contains("log")) { LogCount += 1; } else if (i.Extension.ToLower().Contains("snowpack")) { SnowpackCount += 1; } } } }
public virtual void btnPreview_Click(object sender, EventArgs e) { using (NetworkShareAccesser.Access("PLGUNV_NAS", @"", "pitd.is_user", "Apple_01")) { StaticSettings staticSettings = new StaticSettings(); UnitOfWork unitOfWork = new UnitOfWork(); var root = $@"\\plgunv_nas\is_docs\ofmis\{staticSettings.Offices.OffcAcr}"; if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } var files = unitOfWork.FilesRepo.Find(x => x.RefId == documentActions.Id && x.TableName == "Action"); if (files == null) { return; } var path = Path.Combine(root, files.Path + ".png"); frmPreviewer frm = new frmPreviewer(path); frm.ShowDialog(); } }
protected void Page_Load(object sender, EventArgs e) { string servername = ConfigurationManager.AppSettings["ServerName"].ToString(); string domainame = ConfigurationManager.AppSettings["DomainName"].ToString(); string username = ConfigurationManager.AppSettings["UserName"].ToString(); string password = ConfigurationManager.AppSettings["Password"].ToString(); try { using (NetworkShareAccesser.Access(servername, domainame, username, password)) { string path = Session["path"].ToString(); // string path = Request.QueryString["val"].ToString(); if (!(string.IsNullOrEmpty(path))) { string extention = Path.GetExtension(path); int len = extention.Length - 1; string extwithoutdot = extention.Substring(1, len); if (extwithoutdot.Equals("JPG") || extwithoutdot.Equals("jpg") || extwithoutdot.Equals("jpeg") || extwithoutdot.Equals("JPEG")) { extwithoutdot = "jpeg"; } if (extwithoutdot.Equals("TIF") || extwithoutdot.Equals("tif")) { extwithoutdot = "tiff"; } if (extwithoutdot.Equals("GIF") || extwithoutdot.Equals("gif")) { extwithoutdot = "gif"; } if (extwithoutdot.Equals("BMP") || extwithoutdot.Equals("bmp")) { extwithoutdot = "bmp"; } string filetype = ""; if (extention.Equals(".pdf") || extention.Equals(".PDF")) { extwithoutdot = "pdf"; filetype = "PDF"; } WebClient client = new WebClient(); Byte[] buffer = client.DownloadData(path); if (buffer != null) { if (filetype.Equals("PDF")) { Response.ContentType = "application/" + extwithoutdot; } else { Response.ContentType = "image/" + extwithoutdot; } Response.AddHeader("content-length", buffer.Length.ToString()); Response.BinaryWrite(buffer); } } //buffer.Flush(); //take care of buffer and try to clear it. } } catch (Exception ex) { //log.Error("DisplayPdf.cs : Exception caught"); //log.Error(" Error Message" + ex); //log.Error(" Stack Trace " + ex.StackTrace); ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Not able to view the requested document- Please contact support team')", true); } }