static void test() { try { string ipaddress = "192.168.67.215"; string hostServer = @"\\" + ipaddress + @"\monitor\"; // NetworkShare.ConnectToShare(hostServer, "atladmin", "7mmT@XAy"); //Connect with the new credentials NetworkShare.ConnectToShare(@"\\192.168.67.215\monitor", "atladmin", "7mmT@XAy"); string filepath = ("C:\\webs\\atl_pbx_web\\recordings\\"); DirectoryInfo diSource = new DirectoryInfo(hostServer); DirectoryInfo diTarget = new DirectoryInfo(filepath); foreach (FileInfo wav_file in diSource.GetFiles()) { if (wav_file.CreationTime < DateTime.Now.AddMinutes(-13)) { if (File.Exists(Path.Combine(diTarget.FullName, wav_file.Name))) { File.Delete(Path.Combine(diTarget.FullName, wav_file.Name)); } wav_file.MoveTo(Path.Combine(diTarget.FullName, wav_file.Name)); WriteToFile("Successfully moved file... " + wav_file.Name); } } NetworkShare.DisconnectFromShare(hostServer, false); //Disconnect from the server. } catch (Exception ex) { WriteToFile(ex.Message.ToString()); } }
private void frmLoaderFile1C_Load(object sender, EventArgs e) { DataTable conf = Config.hCntMain.EditGetConf(ConnectionSettings.GetIdProgram(), "", ""); EnumerableRowCollection <DataRow> rowCollect = conf.AsEnumerable().Where(r => r.Field <string>("id_value").Equals("psss")); if (rowCollect.Count() > 0) { net = new NetworkShare(true, false); net.ConnectToShare(); pathSign = rowCollect.First()["value"].ToString() + "\\sign"; if (!Directory.Exists(pathSign)) { MessageBox.Show(Config.centralText("Программа не обнаружила\nкаталога с подписями\nарендодателей.\nЗагрузка счетов 1С невозможна.\n"), "Загрузка счетов", MessageBoxButtons.OK, MessageBoxIcon.Warning); Close(); return; } } }
protected void Page_Load(object sender, EventArgs e) { try { if (Session[Constants.NameSessionUser] == null) { Utilities.logout(Page.Session, Page.Response); } else { _user = (Users)Session[Constants.NameSessionUser]; } if (!IsPostBack) { Session[_nombreSession] = null; } if (Request.Params["numero"] != null && Request.Params["rutapdf"] != null) { _nodoc = Request.Params["numero"].ToString(); _rutapdf = Request.Params["rutapdf"].ToString(); NetworkShare.ConnectToShare(@"\\10.10.10.30\FileRepositorySS", "Administrator", "adminBata."); //System.IO.FileInfo file = new System.IO.FileInfo(@_rutapdf); //if ((file.Exists)) //{ Response.Clear(); //Response.AddHeader("Content-Disposition", "attachment; filename=" + _nodoc + ".pdf"); ////Response.AddHeader("Content-Length", file.Length.ToString()); //Response.ContentType = "Application/pdf"; ////Response.TransmitFile(Server.MapPath(_rutapdf)); //Response.WriteFile(_rutapdf); string pdfPath = _rutapdf; WebClient client = new WebClient(); Byte[] buffer = client.DownloadData(@pdfPath); Response.AddHeader("Content-Disposition", "attachment; filename=" + _nodoc + ".pdf"); Response.ContentType = "application/pdf"; Response.AddHeader("content-length", buffer.Length.ToString()); Response.BinaryWrite(buffer); Response.End(); Response.Close(); //file = null; //} //Set the appropriate ContentType. //Response.ContentType = "Application/pdf"; ////Get the physical path to the file. //string FilePath = MapPath(_rutapdf + ".pdf"); ////Write the file directly to the HTTP content output stream. //Response.WriteFile(FilePath); //Response.End(); //HttpContext.Current.Response.Clear(); //HttpContext.Current.Response.ContentType = "application/pdf"; ////Response.Clear(); ////Response.ContentType = "application/pdf"; //HttpContext.Current.Response.AddHeader( // "content-disposition", string.Format("attachment; filename={0}", _nodoc + ".pdf")); //HttpContext.Current.Response.End(); //Response.AppendHeader("Content-Disposition", "attachment; filename=" + _nodoc + ".pdf"); //Response.TransmitFile(_rutapdf); //Response.End(); } } catch (Exception ex) { this.msnMessage.LoadMessage(ex.Message, ucMessage.MessageType.Error); //throw new Exception(msgErr.Message, msgErr.InnerException); //Response.Redirect("panelReturns.aspx"); } }
static void Main(string[] args) { System.Threading.Thread.Sleep(10000); try { // FOR TEST ONLY: if (false) { args = new string[6]; args[0] = "Database=LinkManager"; args[1] = "ClientName=LinkManager"; args[2] = "DatabaseProvider=System.Data.SqlClient"; args[3] = "ConnectionString=Data%20Source%3D.%5CStandard%3BInitial%20Catalog%3DLinkManager%3BIntegrated%20Security%3DTrue"; args[4] = "FileName=C%3A%5CProjects%5CBlueocean%5CLink%5CLinkLibraries%5CLinkManager%5CClients%5CLinkOnline%5CLinkOnline%5CFileadmin%5CClientBackups%5Clinkmanager.xml"; args[5] = "BackupEntryPath=ClientBackups%2FClientBackup%5B%40Id%3D%227c384b95-8d92-4147-bd3c-4949bcceb4c7%22%5D"; } // Run through all command line arguments. foreach (string arg in args) { // Get the name of the argument. string name = arg.Split('=')[0]; // Get the value of the argument. string value = HttpUtility.UrlDecode(arg.Split('=')[1]); switch (name) { case "FileName": fileNameClientBackups = value; break; case "BackupEntryPath": clientBackupEntryPath = value; break; case "Database": databaseName = value; break; case "ClientName": clientName = value; break; case "DatabaseProvider": databaseProvider = HttpUtility.UrlDecode(value); break; case "ConnectionString": connectionString = HttpUtility.UrlDecode(value); break; } } clientUsers = new List <Guid>(); GetClientUsers(); // Build the full path to the backup directory name. string directoryName = Path.Combine( ConfigurationManager.AppSettings["BackupRoot"], DateTime.Now.ToString("yyyy"), DateTime.Now.ToString("MMM"), clientName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") ); if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["Username"])) { if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } // Backup the client's definition files. BackupFileSystem(directoryName); // Backup the client's database. BackupDatabase(Path.Combine( directoryName, clientName + ".bak" )); } else { string error = NetworkShare.ConnectToShare( ConfigurationManager.AppSettings["BackupRoot"], ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"] ); /*using (new NetworkConnection(ConfigurationManager.AppSettings["BackupRoot"], new System.Net.NetworkCredential( * ConfigurationManager.AppSettings["Username"], * ConfigurationManager.AppSettings["Password"] * )))*/ { if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } // Backup the client's definition files. BackupFileSystem(directoryName); string tempFile = Path.GetTempFileName() + ".bak"; // Backup the client's database. BackupDatabase(tempFile); File.Move(tempFile, Path.Combine( directoryName, clientName + ".bak" )); } NetworkShare.DisconnectFromShare( ConfigurationManager.AppSettings["BackupRoot"], false ); } XmlDocument document = new XmlDocument(); document.Load(fileNameClientBackups); XmlNode xmlNode = document.SelectSingleNode(clientBackupEntryPath); xmlNode.Attributes["Status"].Value = "Finished"; xmlNode.Attributes["FinishDate"].Value = DateTime.Now.ToString(); xmlNode.Attributes["BackupPath"].Value = directoryName; document.Save(fileNameClientBackups); string zipPath = Path.Combine( ConfigurationManager.AppSettings["BackupRoot"], "Archives", DateTime.Now.ToString("yyyy"), DateTime.Now.ToString("MMM") ); string zipArchiveName = Path.Combine( zipPath, clientName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip" ); if (!Directory.Exists(zipPath)) { Directory.CreateDirectory(zipPath); } StreamWriter writer = new StreamWriter(zipArchiveName); ZipArchive zipArchive = new ZipArchive(writer.BaseStream, ZipArchiveMode.Create); CreateEntryFromDirectory(zipArchive, directoryName, false); zipArchive.Dispose(); } catch (Exception ex) { XmlDocument document = new XmlDocument(); document.Load(fileNameClientBackups); XmlNode xmlNode = document.SelectSingleNode(clientBackupEntryPath); xmlNode.Attributes["Status"].Value = "Failed"; xmlNode.Attributes["FinishDate"].Value = DateTime.Now.ToString(); xmlNode.Attributes["BackupPath"].Value = ""; xmlNode.InnerXml = ex.ToString(); document.Save(fileNameClientBackups); } }