国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

uploadify控件使用在.net

2019-11-17 02:03:16
字體:
來源:轉載
供稿:網友

uploadify控件使用在.net

第一次是博客,還有丟丟小興奮呢。作為一個資深菜鳥,為了給自己留下點什么,開始記錄一些技術問題。當然也是學習過程。

   下面是成品的在.net web下的應用,還有很多不足的地方,期待大家的點評。

$(document).ready(function() { $("#uploadify").uploadify({ 'buttonText':'選擇文件', 'swf': '../scripts/jquery.uploadify-v3.2/uploadify.swf?ver=<%=DateTime.Now.Ticks %>', 'uploader': 'UploadHandler.aspx',//上傳后對文件的處理頁 'auto': false,//是否自動上傳 'multi': true,//是否可以上傳多個文件 'fileSizeLimit' : 204800, 'method' : "POST", 'formData' : {'fileID' : <%="'"+Request["file_id"] + "'"%>}, 'onSelect': function(fileObj) { if(fileObj.name.indexOf('%') < 0) {//這是我自己應用的一個方法,在數據庫里判斷是否有重復文件。 AjaxSendPost('IsFileExist.aspx',<%= "'file_id=" + Request["file_id"] + "'"%> + '&file_name=' + fileObj.name + '&file_size='+fileObj.size,IsFileExist); } else { $('#uploadify').uploadify('cancel', '*'); alert("文件名中含有非法字符(%)"); } }, 'onUploadSuccess':function(file,data,response){//處理上傳成功后的事件 }, 'onCancel':function(){//取消上傳或者點擊右上角X的方法 } }); function IsFileExist(){ if(ajaxHttPRequest.readyState==4&&ajaxHttpRequest.status==200){ if(ajaxHttpRequest.responseText == "2") { alert("文件已經存在,按上傳將覆蓋已有文件!"); } else if (ajaxHttpRequest.responseText == "1") { $('#uploadify').uploadify('cancel', '*'); alert("文件已經存在!"); } } } });

  cs文件處理:(UploadHandler.aspx.cs)

  protected void Page_Load(object sender, EventArgs e) {

  HttpPostedFile PostedFile = Request.Files["Filedata"];

     string VirtualDIR = ConfigurationManager.AppSettings["VirtualDIR"];

   string uploadPath = HttpContext.Current.Server.MapPath(VirtualDIR);

    string AttchementuploadPath = HttpContext.Current.Server.MapPath(VirtualDIR + "/Attchements/");

    string MemouploadPath = HttpContext.Current.Server.MapPath(VirtualDIR + "/Memos/");

     string EvaluationUploadPath = HttpContext.Current.Server.MapPath(VirtualDIR + "/Evaluations/");

  DateTime TimeStamp = DateTime.Now;

   if (PostedFile != null)

     {

         if (!string.IsNullOrEmpty(Request["fileID"]))

         {

           int file_id = int.Parse(Request["fileID"]);

           string FullFileName = uploadPath + "http://" + PostedFile.FileName;

       if (!Directory.Exists(uploadPath))

         {

             Directory.CreateDirectory(uploadPath);

        }

          PostedFile.SaveAs(FullFileName);

//下面這句代碼缺少的話,上傳成功后上傳隊列的顯示不會自動消失

       //context.session[context.Session["userName"].ToString()] = filename;

//context.Response.Write(filename);

   string content = SaveFileContent.GetFileContent(FullFileName);

}

       else

       {

     Response.Write("0");

       }

}

  }

  else

     {

       Response.Write("0");

     }

}

  

順便把保存文件內容的方法寫在這個了(只適合.txt和Word文件啦)

public class SaveFileContent {

   public SaveFileContent()

     { // // TODO: 在此處添加構造函數邏輯 //

    }

public static string GetFileContent(object file_path)

{ string outText = string.Empty;

Word._application oWord = new Word.Application();

    Word._Document oDoc;

object oMissing = System.Reflection.Missing.Value;

    object format = WdSaveFormat.wdFormatDocument;

    object VisiableWindows = false;

object Readonly = true;

try {

oWord.Visible = true;

object fileName = file_path;

oDoc = oWord.Documents.Open(ref fileName, ref format, ref Readonly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref VisiableWindows, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

//oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

outText = oDoc.Content.Text;

oDoc.Close(ref oMissing, ref oMissing, ref oMissing);

oDoc = oWord.Documents.Add(ref fileName, ref oMissing, ref oMissing, ref VisiableWindows);

//oDoc = oWord.Documents.Add(ref fileName, ref oMissing, ref oMissing, ref oMissing);

return outText.ToString();

}

catch (Exception ex)

{

Console.Write(ex.Message);

}

finally

{

oWord.Quit(ref oMissing, ref oMissing, ref oMissing);

}

return "";

}

}

就不展示結果啦~~

把3.2的具體參數放在這了,以便查找!!

http://blog.sina.com.cn/s/blog_5079086b0101fkmh.html

  


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 揭西县| 陕西省| 巧家县| 石家庄市| 西宁市| 贡觉县| 普宁市| 松溪县| 长治县| 翁源县| 博客| 兴山县| 荣昌县| 仁布县| 错那县| 鄂温| 基隆市| 沂水县| 龙口市| 五河县| 西和县| 肥东县| 新巴尔虎左旗| 平乐县| 织金县| 乌拉特后旗| 吉安县| 噶尔县| 板桥市| 滦平县| 荥阳市| 习水县| 民和| 乐山市| 沅陵县| 宜丰县| 大丰市| 门头沟区| 广灵县| 林州市| 西丰县|