http://community.csdn.net/Expert/topic/5587/5587694.xml?temp=.7685358
解决方案 »
- 页面跳转问题
- asp.net 发布问题 关于IIS的配置
- java新手转行入asp
- 奇怪的session
- 自动获取当前时间分别判断出今天是星期几?请高手赐教,
- 我寫程序要用到很多不變的量 要放到服務器 開始我用Session但後來覺得它又不穩定又浪費很多服務器資源,我要改成別的應該怎麼辦?
- 如何实现在新闻录入时在内容的任意地方插入图片形成图片新闻
- 在aspx怎么引用public string getPicurl(string picurl)?
- NET有问题了,重装不了,难道要重装2000吗,谢谢
- 请推荐一些书?
- 做ASP.NET的工资会比软件设计的高吗????
- InstallShield怎么把。NET框架打包进去啊
string filename = filepath.Substring(filepath.LastIndexOf("\\"));
string fileEx = filepath.Substring(filepath.LastIndexOf(".")+1);
string serverpath = "C:/aa/upload/" + filename;
string dbpath = "\\upload\\" + filename;
if (fileEx == "jpg" || fileEx == "bmp" || fileEx == "gif")
{
FileUpload1.PostedFile.SaveAs(serverpath);
Response.Write("成功");
Image1.ImageUrl = @"..\aa\upload\" + filename;
}
else
{
Response.Write("失敗");
}
string sql = "insert into gc_carno(id,carno,model,carphoto) values(100,'"+TextBox1.Text+"','"+TextBox2.Text+"','"+dbpath+"')";
OracleConnection conn = sda.getoracleconnection();
conn.Open();
OracleCommand cmd = new OracleCommand(sql,conn); int i = cmd.ExecuteNonQuery();
if (i == 1)
{
Response.Write("<script language='javascript'>alert('添加成功')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('添加失敗')</script>");
}
string sThumbNailFileName,ImageFormat oFormat)
{ try
{
System.Drawing.Image oImg = System.Drawing.Image.FromFile(sPhysicalPath + @"\" + sOrgFileName); System.Drawing.Image oThumbNail = new Bitmap(this.ThumbNailSize.Width,
this.ThumbNailSize.Height, oImg.PixelFormat); Graphics oGraphic = Graphics.FromImage(oThumbNail); oGraphic.CompositingQuality = CompositingQuality.HighQuality ; oGraphic.SmoothingMode = SmoothingMode.HighQuality ; oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic ; Rectangle oRectangle = new Rectangle(0, 0, this.ThumbNailSize.Width, this.ThumbNailSize.Height); oGraphic.DrawImage(oImg, oRectangle);
oThumbNail.Save(sPhysicalPath + @"\" + sThumbNailFileName,oFormat);
oImg.Dispose(); }
catch (Exception) { } }
<script language="C#" runat="server">
public void DoUpLoad(Object sender,EventArgs e)
{
if(UploadFiles1.Value=="")
{
show.Text="Small pictrue Can't be empty!";
}
else
{
if(UploadFiles2.Value=="")
{
show.Text="Big pictrue Can't be empty!";
}
else
{
int FileCount=Request.Files.Count;
string cun;
for(int i=0;i<FileCount;i++)
{
HttpPostedFile hpf=Request.Files[i];
if(hpf.ContentLength>200000)
{
show.Text="The files can't be more than 200KB!";
break;
}
else
{
hpf.SaveAs(Server.MapPath("./uploadphoto/")+"\\"+DateTime.Now.ToString("yyyyMMddHHmms")+i+".jpg");
cun="uploadphoto/"+DateTime.Now.ToString("yyyyMMddHHmms");
showOK(cun);
}
}
}
}
}
public void showOK(string neirong)
{
tu_small.Text=neirong+"0.jpg";
tu_big.Text=neirong+"1.jpg";
showjg.Text="The pictures's way must not be modified,please do not renovate the web page!";
show.Text="";
}
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<link href="../images/new.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-color: #F5F5F5;
}
.style1 {color: #CC0000}
-->
</style>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4%" height="44"> </td>
<td width="94%" valign="middle"><span class="style1">Add new product →</span></td>
<td width="2%"> </td>
</tr>
<tr>
<td height="248"> </td>
<td valign="top" bordercolor="#55A0FF"> <table width="100%" border="0" cellspacing="1" cellpadding="0">
<form runat="server">
<tr>
<td width="12%">Upload pictrue </td>
<td width="88%" colspan="4"><table width="100%" height="41" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="13%" align="center">Small one </td>
<td width="37%"><input type="file" id="UploadFiles1" runat="server"></td>
<td width="7%" rowspan="2" align="center">
<input type="submit" value="UpLoad" OnServerClick="DoUpLoad" runat="server" style="width:50; height:40; background-color: #000000;color:#ffffff;"></td>
<td width="43%" rowspan="2">
<asp:Label ID="show" runat="server" ForeColor="#009900"/> </td>
</tr>
<tr>
<td align="center">Big one</td>
<td><input type="file" id="UploadFiles2" runat="server"></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="5">
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td width="51%" height="24">
Small one' way : <asp:Label ID="tu_small" runat="server"/><br>
Big one' way : <asp:Label ID="tu_big" runat="server"/> </td>
<td width="49%"><asp:Label ID="showjg" runat="server" ForeColor="#CC0000"/></td>
</tr>
</table> </td>
</tr>
<tr valign="top">
<td height="168" colspan="5"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="1" colspan="2" bgcolor="#000000"></td>
</tr>
<tr>
<td width="67%" height="278" align="left" valign="middle"><br>
</td>
<td width="33%" align="left" valign="top">
</td>
</tr>
</table></td>
</tr>
</form>
</table> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void bt_upload_Click(object sender, EventArgs e)
{
try
{
if (FileUpload1.PostedFile.FileName == "")
{
this.lb_info.Text = "请选择文件!";
}
else
{
string filepath = FileUpload1.PostedFile.FileName;
string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);
string serverpath = Server.MapPath("images/") + filename; //这里设置文件的保存路径
FileUpload1.PostedFile.SaveAs(serverpath);
this.lb_info.Text = "上传成功!";
}
}
catch (Exception ex)
{
this.lb_info.Text = "上传发生错误!原因是:" + ex.ToString();
}
}
}前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 343px">
<tr>
<td style="width: 100px">
单文件上传</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:FileUpload ID="FileUpload1" runat="server" Width="475px" />
</td>
<td style="width: 100px">
<asp:Button ID="bt_upload" runat="server" OnClick="bt_upload_Click" Text="上传" /></td>
</tr>
<tr>
<td style="width: 100px; height: 21px;">
<asp:Label ID="lb_info" runat="server" ForeColor="Red" Width="183px"></asp:Label></td>
<td style="width: 100px; height: 21px">
</td>
</tr>
</table> </div>
</form>
</body>
</html>
还要多文件上传吗?我这有
你的程序里public 后面的partial什么意思?
好像不对吧?
怎么出错?
msdn有啊
看2003行不
这句是说要在项目里加个名为images的文件夹
那怎么行呢
你把你的Msn给我,我晚上问你吧,这会要下班了