文件保存到指定位置(无弹窗)
private string savefile(string content)
{
try
{
#region 保存文章内容为html文件
DateTime dt = DateTime.Now;
//设置文件夹路径
string directory = @"D:\";
//文件名称 以时间命名 避免重名
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString() + dt.Millisecond.ToString();
//文件扩展名 可根据具体需要修改
string othername = @".html";
//文件保存完整路径
string path = directory + filename + othername;
//验证文件夹是否存在 不存在则创建
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
//以创建文件的方式写入内容
FileStream fs = new FileStream(path, FileMode.CreateNew, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
sw.WriteLine(content);
sw.Close();
fs.Close();
return @"D:/" + filename + othername;//返回文件存储路径
#endregion
}
catch (Exception ex)
{
//错误处理
return "";
}
}
导出Excel到自定义位置
protected void Button1_Click(object sender, EventArgs e)
{
System.Web.HttpContext curContext = System.Web.HttpContext.Current;
if (dt != null)
{
string filename = "档案全宗";
string name1 = filename;
filename = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);
HttpResponse resp = System.Web.HttpContext.Current.Response;
resp.Charset = "utf-8";
resp.Clear();
resp.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
resp.ContentEncoding = System.Text.Encoding.UTF8;
resp.ContentType = "application/ms-excel";
string style ="<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=utf-8\"/>"+ "<style> .table{ font: 9pt Tahoma, Verdana; color: #000000; text-align:center; background-color:#8ECBE8; }.table td{text-align:center;height:21px;background-color:#EFF6FF;}.table th{ font: 9pt Tahoma, Verdana; color: #000000; font-weight: bold; background-color: #8ECBEA; height:25px; text-align:center; padding-left:10px;}</style>";
resp.Write(style);
//resp.Write(ExportTable(list));
resp.Write("<table class='table'><tr><th>" +"文件标题"+ "</th><th>" + "档案类别" + "</th><th>" +"发文日期" + "</th><th>" +"文件链接" + "</th><th>" +"备注" + "</th></tr>");
//VideoList = (List<subShiyongModel>)Session["dbVideoList"];
for(int i=0;i<dt.Rows.Count;i++)
{
resp.Write("<tr><td>" + dt.Rows[i]["FileName"]+ "</td>");
resp.Write("<td>" +dt.Rows[i]["type"]+ "</td>");
resp.Write("<td>" + dt.Rows[i]["fromtime"].ToString()+ "</td>");
resp.Write("<td>" + dt.Rows[i]["url"]+ "</td>");
resp.Write("<td>" + dt.Rows[i]["beizhu"]+ "</td>");
resp.Write("</tr>");
}
resp.Write("<table>");
resp.Flush();
resp.End();
}
HTML控件上传文件JSON
string json = "";
string newfilename = "";
string path = "";
try
{
if (context.Request.Files["file_upload"] != null && context.Request.Files["file_upload"].FileName != "")
{
string hzm = System.IO.Path.GetExtension(context.Request.Files["file_upload"].FileName);//后缀名 如 .doc
string[] a = { ".txt", ".jpg", ".jpeg", ".gif", ".png", ".docx", ".doc", ".xlsx", ".xls", ".rar", ".zip",".pdf" };//设定好了的格式
if (!a.Contains(hzm))
{
json = "{\"statusCode\":\"300\",\"message\":\"文件格式不正确\",\"navTabId\":\"nav6\",\"rel\":\"\",\"callbackType\":\"\",\"forwardUrl\":\"\"}";
return json;
}
else
{
int defaulsize = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["filesize"]);//取得设置的默认文件的大小
int filesize = (context.Request.Files["file_upload"].ContentLength) / 1024; //取得上传的文件的大小,单位为bytes
if (filesize < defaulsize)
{
#region 对文件进行操作
newfilename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + hzm;//文件的新名字 如20120711105734222.doc
path = System.Web.HttpContext.Current.Server.MapPath("~/UploadFile//");//文件保存的路径
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
#endregion
}
else
{
//超过了文件的大小
json = "{\"statusCode\":\"300\",\"message\":\"上传的文件超过了3000M,请重新选择\",\"navTabId\":\"nav6\",\"rel\":\"\",\"callbackType\":\"\",\"forwardUrl\":\"\"}";
return json;
}
}
}
}
catch (Exception)
{
json = "{\"statusCode\":\"300\",\"message\":\"文件格式不正确\",\"navTabId\":\"nav6\",\"rel\":\"\",\"callbackType\":\"\",\"forwardUrl\":\"\"}";
return json;
}
if (newfilename != "")
{
context.Request.Files["file_upload"].SaveAs(path + newfilename); //保存文件
}
uploadFile控件上传文件,格式判断
控件UpdloadFile文件上传eg:
string newfilename = file_uploadid.FileName;
string size = file_uploadid.PostedFile.ContentLength.ToString();
string type = file_uploadid.PostedFile.ContentType;
string type2 = newfilename.Substring(newfilename.LastIndexOf(".") + 1);
string path = "";
try
{
if (file_uploadid.PostedFile != null && file_uploadid.PostedFile.FileName != "")
{
string hzm = System.IO.Path.GetExtension(file_uploadid.PostedFile.FileName);//后缀名 如 .doc
string[] a = { ".txt", ".jpg", ".jpeg", ".gif", ".png", ".docx", ".doc", ".xlsx", ".xls", ".rar", ".zip", ".pdf" };//设定好了的格式
if (!a.Contains(hzm))
{
Response.Write("文件格式不正确");
}
else
{
int defaulsize = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["filesize"]);//取得设置的默认文件的大小
int filesize = (file_uploadid.PostedFile.ContentLength) / 1024; //取得上传的文件的大小,单位为bytes
if (filesize < defaulsize)
{
#region 对文件进行操作
newfilename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + hzm;//文件的新名字 如20120711105734222.doc
path = System.Web.HttpContext.Current.Server.MapPath("~/UploadFile//");//文件保存的路径
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
#endregion
}
else
{
//超过了文件的大小
Response.Write("上传的文件超过了3000M,请重新选择 ");
}
}
}
}
catch (Exception)
{
Response.Write("文件格式不正确");
}
#endregion
if (newfilename != "")
{
file_uploadid.SaveAs(path + newfilename); //保存文件
}
服务器控件分页
HTML控件分页:
LoadRankUnitPrice()
{
int PageNow = Convert.ToInt32(currentpage.Text);//当前页
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dtcol.DefaultView;
pds.AllowPaging = true;//允许分页
pds.PageSize = 20;//每页显示20条数据
pds.CurrentPageIndex = PageNow - 1;//取得当前页的页码
First.Enabled = true;
Front.Enabled = true;
Next.Enabled = true;
Last.Enabled = true;
if (PageNow == 1)
{
First.Enabled = false;
Front.Enabled = false;
}
if (PageNow == pds.PageCount)
{
Next.Enabled = false;
Last.Enabled = false;
}
this.allpage.Text = Convert.ToString(pds.PageCount);//共多少页
this.alldata.Text = Convert.ToString(dt.Rows.Count);
this.docment.DataSource = pds;
docment.DataBind();
}
protected void First_Click(object sender, EventArgs e)
{
this.currentpage.Text = "1";
this.LoadRankUnitPrice();
}
/// <summary> 上一页</summary>
protected void Front_Click(object sender, EventArgs e)
{
this.currentpage.Text = Convert.ToString(Convert.ToInt32(currentpage.Text) - 1);
this.LoadRankUnitPrice();
}
/// <summary> 下一页</summary>
protected void Next_Click(object sender, EventArgs e)
{
this.currentpage.Text = Convert.ToString(Convert.ToInt32(currentpage.Text) + 1);
this.LoadRankUnitPrice();
}
/// <summary> 尾页</summary>
protected void Last_Click(object sender, EventArgs e)
{
this.currentpage.Text = this.allpage.Text;
this.LoadRankUnitPrice();
}
JS验证是否输入为数字
js 是否为数字 function MustNumber()
{ if (((event.keyCode >= 48) && (event.keyCode <= 57)) || (event.keyCode == 46)) { event.returnValue = true; } else { event.returnValue = false; } }
c++ 课程实践
c++ 课程实践。。通讯录 ,用c++写的可实现添加、删除、修改、查找、显示输入的或者存入磁盘的电话号码
ACM c++ 10进制转换为2进制
ACM 超大数的动态数组 10进制转换为2进制。
jsp获取系统时间
用jsp简单的获取系统时间,年月日,其他的可以自己添加