2011年5月13日

最近使用的一个大文件上传组件RadUpLoad(带进度条时间显示)

 private string SaveFile()
    {
        string _return = "";
        foreach (UploadedFile file in RadUploadContext.Current.UploadedFiles)
        {

            string Path = Server.MapPath(@"/upload/media");

            //如果路径不存在,则创建
            if (System.IO.Directory.Exists(Path) == false) 
            {
                System.IO.Directory.CreateDirectory(Path);
            }

            //组合路径,file.GetName()取得文件名
            Path = Path + "/" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + "." + file.GetExtension();

            //保存
            file.SaveAs(Path, true);
            _return = Path;
        }
        return _return;
    }
 此处代码要在上面增加
using Telerik.WebControls;
 

前台代码:
顶部注册组件
<%@ Register TagPrefix="telerik" Namespace="Telerik.QuickStart" Assembly="Telerik.QuickStart" %>
<%@ Register TagPrefix="radU" Namespace="Telerik.WebControls" Assembly="RadUpload.Net2" %>
页面HTML
<radU:RadProgressManager ID="Radprogressmanager1" Width="100%" runat="server" />
<radU:RadProgressArea ID="progressArea1" Width="100%" runat="server">
</radU:RadProgressArea>
<asp:FileUpload ID="FileUpload1" Width="180" runat="server" />
引用DLL为RadUpload.Net2.dll与 Telerik.QuickStart.dll ,RadUpload.Net2.xml都在BIN目录下

webconfig配置

   <httpModules>

      <add name="RadUploadModule" type="Telerik.WebControls.RadUploadHttpModule, RadUpload.Net2"/>
    </httpModules>
 <httpHandlers>
 <add verb="*" path="Telerik.RadUploadProgressHandler.aspx" type="Telerik.WebControls.RadUploadProgressHandler, RadUpload.Net2"></add>
  </httpHandlers>
<!--此处必须有要httpRuntime配置,否则报DNSerror,而不能上传-->
<httpRuntime maxRequestLength="2097151" executionTimeout="3600"/>
 

Bin文件下载:下载文件

posted @ 2011-05-13 16:20 幽幽南山下 阅读(411) 评论(0) 编辑

2011年4月11日

最近面试遇到的关于字符串的输出查找题目

/// <summary>
/// 输出第一个只出现一次的字母
/// </summary>
private static void OutPutTheFirstLetter()
{
string a = Console.ReadLine();
byte[] array = System.Text.Encoding.ASCII.GetBytes(a);
int b = -1;
for (int i = 0; i < array.Length; i++)
{
for (int j = i + 1; j < array.Length; j++)
{
if (array[i].ToString() == array[j].ToString())
{
b
= i;
goto Found;


}
}
}
Found:
if (b == -1)
{
Console.WriteLine(
"未找到");
Console.ReadKey();
}
else
{
Console.WriteLine(System.Text.Encoding.ASCII.GetString(array, b,
1));
Console.ReadKey();
}

}
/// <summary>
/// 输入字符串 倒序输出
/// </summary>
private static void OutPutDesc()
{
string a = Console.ReadLine();

byte[] array = System.Text.Encoding.ASCII.GetBytes(a);
byte[] arr2 = new byte[array.Length];
for (int i = 0; i < array.Length; i++)
{
arr2[i]
= array[array.Length - i - 1];
}
Console.WriteLine(System.Text.Encoding.ASCII.GetString(arr2));
Console.ReadKey();
}

posted @ 2011-04-11 12:52 幽幽南山下 阅读(140) 评论(0) 编辑

2010年12月23日

JQuery分页组件

 

代码








//每次只显示5个页码
(function($) {
//设定页码方法,初始化
$.fn.setPager = function(options) {
var opts = $.extend({}, pagerDefaults, options);
return this.each(function() {
$(
this).empty().append(setPagerHtml(parseInt(options.RecordCount), parseInt(options.PageIndex), options.buttonClick));

});
};
//设定页数及html
function setPagerHtml(RecordCount, PageIndex, pagerClick) {

var $content = $("<ul class=\"pages\"></ul>");
var startPageIndex = 1;
//若页码超出
if (RecordCount <= 0) RecordCount = pagerDefaults.PageSize;
//末页
var endPageIndex = parseInt(RecordCount % parseInt(pagerDefaults.PageSize)) > 0 ? parseInt(RecordCount / parseInt(pagerDefaults.PageSize)) + 1 : RecordCount / parseInt(pagerDefaults.PageSize)

if (PageIndex > endPageIndex) PageIndex = endPageIndex;
if (PageIndex <= 0) PageIndex = startPageIndex;
var nextPageIndex = PageIndex + 1;
var prevPageIndex = PageIndex - 1;
if (PageIndex == startPageIndex) {
$content.append($(
"<li><span class=\"beginEnd\">首页</span></li>"));
$content.append($(
"<li><span class=\"beginEnd\">上一页</span></li>"));
}
else {

$content.append(renderButton(RecordCount,
1, pagerClick, "首页"));
$content.append(renderButton(RecordCount, prevPageIndex, pagerClick,
"上一页"));
}
//这里判断是否显示页码
if (pagerDefaults.ShowPageNumber) {
// var html = "";
//页码部分隐藏 只显示中间区域
if (endPageIndex <= 5 && PageIndex <= 5) {
for (var i = 1; i <= endPageIndex; i++) {
if (i == PageIndex) {
$content.append($(
"<li><span class=\"current\">" + i + "</span></li>"));
}
else {
$content.append(renderButton(RecordCount, i, pagerClick, i));
}

}

}
else if (endPageIndex > 5 && endPageIndex - PageIndex <= 2) {

$content.append($(
"<li class=\"dotted\">...</li>"));
for (var i = endPageIndex - 4; i <= endPageIndex; i++) {
if (i == PageIndex) {
$content.append($(
"<li><span class=\"current\">" + i + "</span></li>"));
}
else {
$content.append(renderButton(RecordCount, i, pagerClick, i));
}

}
}
else if (endPageIndex > 5 && PageIndex > 3) {

$content.append($(
"<li class=\"dotted\">...</li>"));
for (var i = PageIndex - 2; i <= PageIndex + 2; i++) {
if (i == PageIndex) {
$content.append($(
"<li><span class=\"current\">" + i + "</span></li>"));
}
else {
$content.append(renderButton(RecordCount, i, pagerClick, i));
}

}
$content.append($(
"<li class=\"dotted\">...</li>"));

}
else if (endPageIndex > 5 && PageIndex <= 3) {

for (var i = 1; i <= 5; i++) {
if (i == PageIndex) {
$content.append($(
"<li><span class=\"current\">" + i + "</span></li>"));
}
else {
$content.append(renderButton(RecordCount, i, pagerClick, i));
}

}
$content.append($(
"<li class=\"dotted\">...</li>"));
}
}
if (PageIndex == endPageIndex) {
$content.append($(
"<li><span class=\"beginEnd\">下一页</span></li>"));
$content.append($(
"<li><span class=\"beginEnd\">末页</span></li>"));
}
else {
$content.append(renderButton(RecordCount, nextPageIndex, pagerClick,
"下一页"));
$content.append(renderButton(RecordCount, endPageIndex, pagerClick,
"末页"));
}


return $content;
}
function renderButton(recordCount, goPageIndex, EventHander, text) {
var $goto = $("<li><a title=\"" + goPageIndex + "页\">" + text + "</a></li>\"");
$goto.click(function() {

EventHander(recordCount, goPageIndex);
});
return $goto;
}
var pagerDefaults = {
DefaultPageCount: 1,
DefaultPageIndex: 1,
PageSize: 20,
ShowPageNumber: true //是否显示页码
};
})(jQuery);

 

 

     自己模仿别人写的一个JQ分页插件,代码简单易懂,欢迎下载使用。下面为效果

 

 

下载地址:jquery-pager-1.0分页下载

posted @ 2010-12-23 15:22 幽幽南山下 阅读(925) 评论(9) 编辑