Asp.net上传文件,过滤不切合须求格式的公文

图片 1图片 2

 

 

数据库部分

 放在四个阵列中,如:

 

 <input type="button" value="重新生成JSON" class="button1" id="createjson" />

 

 

[{"id":31,"name":"\u65b0\u95fb\u4e2d\u5fc3","pid":0,"itemvalue":"|0|"},
{"id":51,"name":"\u4f01\u4e1a\u5feb\u8baf","pid":31,"itemvalue":"|0|31|"},
{"id":52,"name":"\u4f01\u4e1a\u516c\u544a","pid":31,"itemvalue":"|0|31|"},
{"id":53,"name":"\u884c\u4e1a\u52a8\u6001","pid":31,"itemvalue":"|0|31|"},
{"id":91,"name":"\u65b0\u95fb\u4e2d\u5fc3","pid":31,"itemvalue":"|0|31|"},
{"id":93,"name":"\u4f01\u4e1a\u5feb\u8baf","pid":31,"itemvalue":"|0|31|"},
{"id":94,"name":"\u4f01\u4e1a\u516c\u544a","pid":31,"itemvalue":"|0|31|"},
{"id":180,"name":"\u6d4b\u8bd5","pid":31,"itemvalue":"|0|31|"},
{"id":181,"name":"\u6d4b\u8bd5111","pid":31,"itemvalue":"|0|31|"},


{"id":54,"name":"\u5173\u4e8e\u76df\u53cb\u634c\u634c","pid":0,"itemvalue":"|0|"},
{"id":55,"name":"\u4f01\u4e1a\u6982\u51b5","pid":54,"itemvalue":"|0|54|"},
{"id":56,"name":"\u4f01\u4e1a\u6587\u5316","pid":54,"itemvalue":"|0|54|"},
{"id":57,"name":"\u4f01\u4e1a\u53d1\u5c55","pid":54,"itemvalue":"|0|54|"}
......
]

        //假如检查实验到上传文件切合格式必要,管理接下去的事体。
    }

 protected void Button1_Click(object sender, EventArgs e)
    {
        if (!File.Exists(this.FileUpload1.PostedFile.FileName))
        {
            //follow Js class, download address:
            Insus.NET.InsusJsUtility objJs = new Insus.NET.InsusJsUtility();
            objJs.JsAlert(“You did not specify a file.”);
            return;
        }

后台代码

 protected void Button1_Click(object sender, EventArgs e)
    {
       //判定顾客是还是不是有取舍三个文书。
        if (!File.Exists(this.FileUpload1.PostedFile.FileName))
        {           
            objJs.JsAlert(“You did not specify a file.”);
            return;
        }

 

运作结果
common/newscategoryJson.js

 string GetFileCass(string path)
    {
        try
        {
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            BinaryReader reader = new BinaryReader(fs);
            string fileClass = string.Empty;
            byte buffer;

 /// <summary>    /// 得到汉字的Unicode编码    /// </summary>    protected string GetUnicode(string text)    {        string result = "";        for (int i = 0; i < text.Length; i++)        {            if ((int)text[i] > 32 && (int)text[i] < 127)            {                result += text[i].ToString();            }            else                result += string.Format("\\u{0:x4}", (int)text[i]);        }        return result;    }

 

            return fileClass;
        }
        catch
        {
            return string.Empty;
        }
    }

1、Server.MapPath(string path);

末段在上传铵钮Click事件写代码,仅供参照他事他说加以考察:

按键事件:

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图