上传文档

namespace JngsWeb.Web.Interface
{
public partial class postnotifyfile : System.Web.UI.Page
{
MultipartDataInfo mdi;
protected void Page_Load(object sender, EventArgs e)
{
if (this.Request.HttpMethod.Equals("POST"))
{
SendResponse(Response, Dopost());
}
}
private string Dopost()
{
JsonData jd = new JsonData();
JsonBase.AddJsonProperty("result", ref jd);
try
{
if (this.Request.HttpMethod.Equals("POST"))
{
string task_id, attach_name, attach_url;
string img = "";
//DbHelperSQL.RecordError("postnotifyfile", "ttt");

mdi = new MultipartDataInfo();
mdi.CollectFormDatas();

Dictionary<string, string> dc = new Dictionary<string, string>();
//string parent_id = mdi.FormCollections["parent_id"].ToString();
task_id = mdi.FormCollections["notify_id"].ToString();
//dc.Add("tousuid", task_id);

if (mdi.FileCount > 0)
{
mdi.Save();
//string att = Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, "");
//string local_attach_name = mdi.FileCollections["image"].FileName;
//attach_name = mdi.FormCollections["attach_name"].ToString();
//attach_url = att + Request.ApplicationPath + "/filehtml/" + local_attach_name;
// dc.Add("attach_name", attach_name);

// dc.Add("attach_url1", attach_url);

foreach (MyFileInfo mfi in mdi.FileCollections)
{
string att = Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, "");
string local_attach_name = mdi.FileCollections["image"].FileName;
attach_name = mdi.FormCollections["attach_name"].ToString();
attach_url = att + Request.ApplicationPath + "/filehtml/" + local_attach_name;
if (string.IsNullOrEmpty(img))
{
img = attach_url;
}
else
{
img = "" + img + "," + attach_url + "";
}
string sql = "select * from officeurl1 where tousuid=" + task_id + "";
var dt = BaseDal.QueryDataTable(sql);
if (dt.Rows.Count == 0)
{
dc.Add("tousuid", task_id);
dc.Add("attach_name", attach_name);

dc.Add("attach_url1", img);

int lastid = BaseDal.InsertToTable("officeurl1", dc);
JsonData js = new JsonData();
JsonBase.AddKeyValueToJsonObject("id", lastid.ToString(), ref js);
jd["result"] = js;
}
else
{
dc.Add("attach_url1", img);
int lastid = BaseDal.UpdateTables("officeurl1", dc, "tousuid=" + task_id);
JsonData js = new JsonData();
JsonBase.AddKeyValueToJsonObject("id", lastid.ToString(), ref js);
jd["result"] = js;

}

}

}
//int itemid =
//int lastid = BaseDal.InsertToTable("officeurl1", dc);
//JsonData js = new JsonData();
//JsonBase.AddKeyValueToJsonObject("id", lastid.ToString(), ref js);
//jd["result"] = js;
}

return jd.ToJson();
}
catch (Exception ex)
{
DbHelperSQL.RecordError(ex.GetType().ToString(), ex.Message);
jd["result"] = new JsonData("{\"id\":\"0\"}");
return jd.ToJson();
}
}
public void SendResponse(System.Web.HttpResponse response, string data)
{
response.Clear();
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.Buffer = true;
response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
response.Cache.SetExpires(DateTime.Now.AddDays(-1));
response.Expires = 0;
response.CacheControl = "no-cache";
response.Cache.SetNoStore();
response.Write(data);
response.Flush();
response.End();
}
public string randomfilename(string ext)
{
string tmp = Guid.NewGuid().ToString() + ext;
return tmp;
}
}
}

posted @ 2018-10-20 09:33  程非成  阅读(118)  评论(0编辑  收藏  举报