?? adddocument.aspx.cs
字號(hào):
using System;
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.Data.SqlClient;
using OfficeAutomatization;
using System.IO;
public partial class AddDocument : System.Web.UI.Page
{
private static string FILEDIR = "\\DesktopModules\\Document\\Attachments";
protected void Page_Load(object sender, EventArgs e)
{
///
}
protected void AddBtn_Click(object sender, EventArgs e)
{
///如果頁(yè)面輸入內(nèi)容合法
if (Page.IsValid == true)
{
///定義類
OfficeAutomatization.Document document = new OfficeAutomatization.Document();
try
{
///添加新數(shù)據(jù)
document.AddDocument(Desn.Text.Trim(),Body.Text,
Int32.Parse(Session["UserID"].ToString()),
Author.Text.Trim(),
FromSource.Text,
UploadAttachment(),
Remark.Text);
///顯示操作結(jié)果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONADDSUCCESSMESSAGE + "')</script>");
}
catch (Exception ex)
{
///顯示添加操作中的失敗、錯(cuò)誤信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n", " "));
}
}
}
protected void ReturnBtn_Click(object sender, EventArgs e)
{
///返回管理頁(yè)面
Response.Redirect("~/DesktopModules/Document/DocumentManage.aspx");
}
private string UploadAttachment()
{
if (AttachmentFile.PostedFile.ContentLength > 0)
{
String fileName = AttachmentFile.PostedFile.FileName.Substring(AttachmentFile.PostedFile.FileName.LastIndexOf("\\"),
AttachmentFile.PostedFile.FileName.Length - AttachmentFile.PostedFile.FileName.LastIndexOf("\\"));
String fileTime = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString()
+ DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString()
+ DateTime.Now.Second.ToString() + DateTime.Now.Minute.ToString()
+ DateTime.Now.Millisecond.ToString();
fileName = "\\" + fileTime + GetRandomint() + fileName.Substring(fileName.IndexOf("."), fileName.Length - fileName.IndexOf("."));
string sFileName = Server.MapPath(Request.ApplicationPath) + FILEDIR + fileName;
if (File.Exists(sFileName) == false)
{
try
{
//把文件存入磁盤,如果失敗,導(dǎo)向提示頁(yè)面
AttachmentFile.PostedFile.SaveAs(sFileName);
return ("Attachments" + fileName);
}
catch (Exception ex)
{
string sRawURL = Request.RawUrl;
if (sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0, sRawURL.IndexOf("?"));
}
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n", " "));
}
}
else
{
Response.Write("<script>alert(\"你上傳的文件已經(jīng)存在!\")</script>");
}
}
else
{
Response.Write("<script>alert(\"你輸入的文件的內(nèi)容為空,請(qǐng)重新輸入!\")</script>");
}
return ("");
}
private String GetRandomint()
{
Random random = new Random();
return (random.Next(10000).ToString());
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -