这个页面执行完毕后IE自动关闭是怎么实现的。

vfan2010 2008-03-13 01:21:29
功能是每隔一段时间(通过任务计划实现)服务器自动打开这个页面,然后自动备份数据并打压缩包,再自动传送到ftp服务器上去。
目前我不能执行这个页面,但是他可以完成后自动关闭,我看了代码,不知道为什么会自动把IE关闭掉。
后台代码:(前台没任何特殊性)
using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using System.Net;

public partial class BackupDB_Default : System.Web.UI.Page
{
#region Define Variables
bool isSuccess = false;

string ftpServerIP = "101.101.10.104";//Remote Server
int ftpPort = 21;
string ftpUserID = "T";
string ftpPassword = "abcdef11";

string pBackupDBAndCompressFilesPath = @"D:\DataCenter";
string pBackupDBFileName = "Iridian2#168EW@370$.bak";
string pCompressFileName = "Iridian2#168EW@370$.rar";
#endregion

#region Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Directory.Exists(pBackupDBAndCompressFilesPath))
BackupDatabase();
}
}
#endregion

#region BackupDatabase
private void BackupDatabase()
{
//SQLDMO.dll is a COM Object ,Microsoft SQl Server provider
SQLDMO.Backup pBackup = new SQLDMO.BackupClass();
SQLDMO.SQLServer pSqlServer = new SQLDMO.SQLServerClass();

try
{
pSqlServer.LoginSecure = false;
pSqlServer.Connect("110.110.10.5", "sa", "1111");//Server IP,Database Login UserName and Password
pBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
pBackup.Database = "Iridian2";
pBackup.Files = pBackupDBAndCompressFilesPath + "\\" + pBackupDBFileName;
pBackup.BackupSetName = "Iridian2";
pBackup.BackupSetDescription = "Database Backup";
pBackup.Initialize = true;
pBackup.SQLBackup(pSqlServer);
isSuccess = true;
}
catch (Exception ex)
{
isSuccess = false;
Response.Write(ex.Message);
}
finally
{
pSqlServer.DisConnect();

if (isSuccess)
{
bool isCompressSuccess = false;

if (File.Exists(pBackupDBAndCompressFilesPath + "\\" + pBackupDBFileName))
isCompressSuccess = CompressDBBackupFile(pBackupDBAndCompressFilesPath + "\\" + pBackupDBFileName, pBackupDBAndCompressFilesPath, pCompressFileName);

if (isCompressSuccess)
SendZipFileToAnotherComputer(pCompressFileName);
}
}
}
#endregion

#region CompressDBBackupFile
private bool CompressDBBackupFile(string patch, string rarPatch, string rarName)
{
bool excuteSuccess = false;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process = new Process();
try
{
the_Info = " a " + rarName + " " + patch + " -r -o+ -m5 -pEW#123@";//Set Password:EW#123@
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = @"C:\Program Files\WinRAR\WinRAR.exe";//Winrar install path
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = rarPatch;
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
excuteSuccess = true;
}
catch (Exception ex)
{
excuteSuccess = false;
Response.Write(ex.Message);
}
finally
{
the_Process.WaitForExit();
if (the_Process != null)
{
the_Process.Close();
the_Process = null;
}
}

return excuteSuccess;
}
#endregion

#region SendZipFileToAnotherComputer
private void SendZipFileToAnotherComputer(string filename)
{
FileInfo fileInf = new FileInfo(pBackupDBAndCompressFilesPath + "\\" + filename);
string uri = "ftp://" + ftpServerIP + ":" + ftpPort.ToString() + "/" + fileInf.Name;//FTP Format:ftp://user:password@ftpserver:port/url-path
FtpWebRequest reqFTP;

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.ContentLength = fileInf.Length;

int contentLen;
int buffLength = 2048;//The buffer size is set to 2kb
byte[] buff = new byte[buffLength];
FileStream fs = null;
Stream strm = null;

try
{
fs = fileInf.OpenRead();
strm = reqFTP.GetRequestStream();
contentLen = fs.Read(buff, 0, buffLength);
while (contentLen != 0)
{
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
}
catch (Exception ex)
{
Response.Write("Upload Error:" + ex.Message);
}
finally
{
if (strm != null)
{
strm.Close();
strm = null;
}

if (fs != null)
{
fs.Close();
fs = null;
}

reqFTP.Abort();
}
}
#endregion
}


前台

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="BackupDB_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Backup Database</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
...全文
276 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
vfan2010 2008-03-13
  • 打赏
  • 举报
回复
刚才打电话问了做这个页面的同事,根本没有做关闭的功能。另外一个同事之前说可以的,不知道怎么回事
vfan2010 2008-03-13
  • 打赏
  • 举报
回复
我也没看出来的。
Magic_YJL 2008-03-13
  • 打赏
  • 举报
回复
强烈建议楼主,揭贴给分~
Magic_YJL 2008-03-13
  • 打赏
  • 举报
回复
我看了半天,也没看出来代码有什么特殊的地方能把打开的IE给关掉
不晓得~
难道说这就是编程的最高境界?无码胜有码?
conannb 2008-03-13
  • 打赏
  • 举报
回复
关注 没看出来
ycagri 2008-03-13
  • 打赏
  • 举报
回复
或者是在FtpWebRequest这个类里面有的方法也说不一定,现在公布的代码里面没有哪句是关闭IE的
chenou851123 2008-03-13
  • 打赏
  • 举报
回复
顶一个 jf
Magic_YJL 2008-03-13
  • 打赏
  • 举报
回复
为何不用WinForm做呢,反正都是用任务计划调用
WinForm多简单,自动关闭直接在Form_Load事件里调用Close()方法就OK了
地下室小红叔 2008-03-13
  • 打赏
  • 举报
回复
从代码上确实没看出来 不如上传一个小的文件跟踪下 或许能发现其中奥妙
不过你用js也能关掉啊
ycagri 2008-03-13
  • 打赏
  • 举报
回复
看一看他计划任务是怎么设置的
ycagri 2008-03-13
  • 打赏
  • 举报
回复
mark~~~
vfan2010 2008-03-13
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 Magic_YJL 的回复:]
哈哈,估计楼主快哭了,看到这些留言
[/Quote]
还没。哈哈
vfan2010 2008-03-13
  • 打赏
  • 举报
回复
现在关键不是如何实现,这个功能已经实现了,就是用web。

因为我有另外一个页面,执行完毕也要自动关闭。我自己用的是js方法,但老板希望不要在系统中用不同的方法来处理同样的问题。
尽管我认为js方法更方便。
但是我实在不知道这个页面为什么会自己关掉IE。
Magic_YJL 2008-03-13
  • 打赏
  • 举报
回复
哈哈,估计楼主快哭了,看到这些留言
downmoon 2008-03-13
  • 打赏
  • 举报
回复
其实完全可以用windows service实现, 不需要页面的
lovehongyun 2008-03-13
  • 打赏
  • 举报
回复
0_0
winner2050 2008-03-13
  • 打赏
  • 举报
回复
是关闭还是崩溃,先确定一下先吧。
vfan2010 2008-03-13
  • 打赏
  • 举报
回复
。。。。
xiaoya317 2008-03-13
  • 打赏
  • 举报
回复
呀··
顶下先···
倒分给我吧·····

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧