概述
$(function () {
$(".uploadfile").upload({
action: 'CourseXMLFileUploadHander.ashx',
name: 'xml',
params: {
'type': 'uploadCourseXMLFile',
'rand': Math.random()
},
onSelect: function (self, element) {
this.autoSubmit = false;
var re = new RegExp("(xml){1}quot;, "i");
if (!re.test(this.filename())) {
alert("Only xml file can be uploaded");
}
else {
this.submit();
}
},
onSubmit: function (self, element) {
$('.uploadfile').hide();
$('#ajax_update').parent().show();
//alert('Uploading file...');
},
onComplete: function (data, self, element) {
$('#ajax_update').parent().hide();
$('.uploadfile').show();
self.resetInput();
try {
var ret = data;
if (ret.indexOf("exception") >= 0) {
alert('Upload file exception: ' + eval(data)[0].exception);
}
else {
showSuccess('File is successfully Load.');
uploadSuccess(ret);
}
} catch (err) {
alert(data);
}
}
});
});
==============================================
<asp:Button ID="btnUploadXMLFile" runat="server" Text="LoadXMLFile" CausesValidation="false" CssClass="uploadfile" />
<script src="../js/jquery.ocupload/jquery.ocupload-1.1.2-mod.js" type="text/javascript"></script>
================================================
public class CourseXMLFileUploadHander : IHttpHandler
{
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext context)
{
try
{
HttpPostedFile file = context.Request.Files["xml"];
//string folder = context.Server.MapPath("../UploadedFiles");
string fileName = Path.GetFileName(file.FileName);
if (Path.GetExtension(fileName).ToLower() != ".xml")
{
context.Response.Write(string.Concat(@"[{""exception"":""The uploaded file is not a xml file.""}]"));
return;
}
string content = string.Empty;
using (StreamReader sr = new StreamReader(file.InputStream, System.Text.Encoding.Default))
{
content = sr.ReadToEnd();
}
context.Response.Write(ConvertStr(content));
}
catch (Exception ex)
{
StringBuilder sb = new StringBuilder();
while (ex != null)
{
sb.AppendFormat("\r\n. {0}", ex.Message);
ex = ex.InnerException;
}
context.Response.Write(string.Concat(@"[{""exception"":""", sb.ToString(), @"""}]"));
}
}
private static string ConvertStr(string inputString)
{
string retVal = inputString;
retVal = retVal.Replace("&", "&");
retVal = retVal.Replace(""", """);
retVal = retVal.Replace("<", "<");
retVal = retVal.Replace(">", ">");
//retVal = retVal.Replace(" ", " ");
//retVal = retVal.Replace(" ", " ");
//retVal = retVal.Replace("t", " ");
//retVal = retVal.Replace("r", "<br>");
return retVal;
}
}
最后
以上就是强健信封为你收集整理的ocupload jquery 的应用的全部内容,希望文章能够帮你解决ocupload jquery 的应用所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复