protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
string folderpath=读数据库数据目录;
LinkButton l = (LinkButton)e.Row.FindControl("lnkbt");
l.Attributes.Add("onclick", "javascript:Openfolder('" + folderpath + "')")
//这行代码的javascript怎么写,或者有没有其他更好的方法来调用Openfolder
} public void Openfolder(string folderpath)
{
Process myProcess = new Process();
try
{
myProcess.StartInfo.FileName =folderpath ; myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}
catch (Win32Exception e)
{
if (e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
Console.WriteLine(e.Message + ". Check the path.");
} else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
{
Console.WriteLine(e.Message + ". You do not have permission to print this file.");
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
string folderpath=读数据库数据目录;
LinkButton l = (LinkButton)e.Row.FindControl("lnkbt");
l.CommandName = "OPEN";
l.CommandArgument = folderpath;
}// 再在command事件中处理
protected void GridView1_Rowcommand(....)
{
switch(e.CommandName)
{
case "OPEN":
// 打开名为e.CommandArgument的目录
}}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
switch(e.CommandName.ToLower()){
case "openfloder";
// 这里写打开目录的代码,目录名为 e.CommandArgument.ToString()
break;
}
} protected void GridView1_DataBound(object sender, EventArgs e)
{
string folderpath = 读数据库数据目录; LinkButton l = (LinkButton)e.Row.FindControl("lnkbt");
l.CommandName = "openfloder";
l.CommandArgument = folderpath;
}
调试后没有问题,但是速度很慢,有没有更好的代码能快速打开本地文件开目录的代码?
试用一下。
这行代码如何完善呢?我觉得javascript:应该会快些