标签:
第一次是博客,还有丢丢小兴奋呢。作为一个资深菜鸟,为了给自己留下点什么,开始记录一些技术问题。当然也是学习过程。
下面是成品的在.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 + "\\" + 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
标签:
原文地址:http://www.cnblogs.com/bellablog/p/4387549.html