77 lines
2.9 KiB
C#
77 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using System.IO;
|
|
|
|
namespace FineUIPro.Web.FileManage
|
|
{
|
|
public partial class SaveCAD : System.Web.UI.Page
|
|
{
|
|
public string txtIsoCode, txtIsoId, txtArea, filename;//定义表单数据
|
|
|
|
HttpResponse response = System.Web.HttpContext.Current.Response;
|
|
HttpRequest request = System.Web.HttpContext.Current.Request;
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
txtIsoId = Request.Form["txtIsoId"];//获取文件ID
|
|
txtArea = Request.Form["txtArea"];
|
|
txtIsoCode = Request.Form["txtIsoCode"];
|
|
filename = Request.Form["filename"];
|
|
saveoffice();
|
|
}
|
|
|
|
//保存文档为office
|
|
public void saveoffice()
|
|
{
|
|
System.Web.HttpFileCollection uploadFiles = Request.Files;
|
|
System.Web.HttpPostedFile theFile;
|
|
|
|
|
|
if (uploadFiles.Count == 0)
|
|
{
|
|
Response.Write("没有文件上传!");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
SqlConnection conn = new SqlConnection(BLL.Funs.ConnString);
|
|
if (conn.State == ConnectionState.Closed) conn.Open();
|
|
try
|
|
{
|
|
for (int i = 0; i < uploadFiles.Count; i++)
|
|
{
|
|
theFile = uploadFiles[i];
|
|
if (uploadFiles.GetKey(i) == "ntkofile")//上传文档控件中的文档
|
|
{
|
|
string strcmd = "";
|
|
strcmd = "Update HJGL_PW_IsoInfo Set FileName=@FileName WHERE ISO_ID='" + txtIsoId + "'";
|
|
|
|
if (filename == "" || filename == null)
|
|
{
|
|
filename = "(" + txtArea + ")" + txtIsoCode + ".dwg";
|
|
}
|
|
filename = filename.Replace(":", "."); //上传文件到磁盘,文件名中不允许带:符号
|
|
filename = filename.Replace(@"/", @"-");
|
|
theFile.SaveAs(Server.MapPath("~/FileManage/uploadCADFile/" + filename));
|
|
|
|
SqlCommand objCommand = new SqlCommand(strcmd, conn);
|
|
objCommand.Parameters.Add("@FileName", System.Data.SqlDbType.NVarChar).Value = filename;
|
|
objCommand.ExecuteNonQuery();
|
|
response.Write("文档控件提交的的文档保存到应用服务器磁盘成功!\n");//后台做一写的输出有利用前台监控文档的保存情况
|
|
}
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
conn.Close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |