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 + "\\" + 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
uploadify控件使用在.net的更多相关文章
- Uploadify 控件上传图片 + 预览
jquery的Uploadify控件上传图片和预览使用介绍. 在简单的servlet系统中和在SSH框架中,后台处理不同的,在三大框架中图片预览时费了不少力气,所以下面将两种情况都介绍一下. 1,前台 ...
- ThinkPHP 3.2.3集成uploadify上传控件
uploadify控件有一个坑爹的问题,就是文件上传时会session丢失,官方解释http://www.uploadify.com/documentation/uploadify/using-ses ...
- jquery文件上传控件 Uploadify
(转自 http://www.cnblogs.com/mofish/archive/2012/11/30/2796698.html) 基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同 ...
- 使用Uploadify(UploadiFive)多文件上传控件遇到的坑
最近项目中需要实现多文件上传功能,于是结合需求最终选择了Uploadify这一款控件来实现.相比其他控件,Uploadify具有简洁的界面,功能API基本可以解决大多数需求,又是基于jquery的,配 ...
- jquery文件上传控件 Uploadify 问题记录
Uploadify v3.2.1 首先引用下面的文件 <!--上传控件 uploadify--> <script type="text/javascript" s ...
- jquery上传文件控件Uploadify
基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同时上传,上传进行进度显示,删除已上传文件. 要求使用jquery1.4或以上版本,flash player 9.0.24以上. 有两个 ...
- uploadify上传控件使用
uploadify是JQuery的一个上传插件,实现的效果非常不错,并且带进度显示,我将给大家演示如何使用uploadify进行图片上传, 1.点我下载http://www.uploadify.com ...
- 文件上传~Uploadify上传控件~续(多文件上传)
对于Uploadify文件上传之前已经讲过一次(文件上传~Uploadify上传控件),只不过没有涉及到多文件的上传,这回主要说一下多个文件的上传,首先,我们要清楚一个概念,多文件上传前端Upload ...
- uploadify上传控件中文的乱码解决办法
uploadify上传控件中文的乱码解决办法 网站用的gb2312的编码,用uploadify上传控件上传中文时在IE能部分成功,FF,Chrome则完全失败,查找了一天原因,结果发现是页面编码问题, ...
随机推荐
- python中的tab补全功能添加
用Python时没有tab补全还是挺痛苦的,记录一下添加该功能的方法利人利己 1. 先准备一个tab.py的脚本 shell> cat tab.py #!/usr/bin/python # py ...
- sybase用户管理(创建、授权、删除)
一.登录用户管理:1.创建用户:sp_addlogin loginame, passwd [, defdb] [, deflanguage] [, fullname] [, passwdexp] [, ...
- mysq优化
MySQL调优可以从几个方面来做:1. 架构层:做从库,实现读写分离: 2.系统层次:增加内存:给磁盘做raid0或者raid5以增加磁盘的读写速度:可以重新挂载磁盘,并加上noatime参数,这样可 ...
- android stagefright awesomeplayer 分析
主要调用awesomeplay.cpp的函数来实现音视频等功能,可以说是对awesomeplay.cpp的封装,进一步抽象,然后提供给上层调用,主要的调用者是MediaPlayerService.cp ...
- 学习asp.net Identity 心得体会(连接oracle)
asp.net Identity具体功能暂不在此细说,下面主要介绍几点连接oracle注意的事项, 1.首先下载连接oracle驱动Oracle.ManagedDataAccess.dll和Oracl ...
- 2014年1月9日 Oracle 内存与结构
Oracle启动时为启动一个实例 主要为 实例 SVG 数据库文件 其它文件 1.Oracle: 内存 进程 其他文件 1.1 SVG内存(Cache) 1.1.1 共享池(Shared Poo ...
- Method to fix "Naming information cannot be located because the target principal name is incorrect." for AD replication failure
Assume Failure DC FP01 and Working DC DC01 1. Stop the Key Distribution Center (KDC) service on FP01 ...
- hdu2429Ping pong
Problem Description N(3<=N<=20000) ping pong players live along a west-east street(consider th ...
- js压缩解压工具
参看下面链接:http://js.clicki.cc/
- python之函数的使用
备注:本篇文章主要讲一讲函数及集合的一些常用用法: 一.首先先看下,集合(set): 集合的特点:无序.不重复(这点跟字典有点像) <1>,在需要访问集合的时候,由于集合本身是无序的,所以 ...