用微软的控件 如
File Filed 使他runat=server
用其控件的 saveas方法
File Filed 使他runat=server
用其控件的 saveas方法
解决方案 »
- 安装vs2010到VsaEnv_Setup_x86_chs就卡住不动怎么解决,云端问题??
- 还是session 的问题..................马上给分
- VisualStudio2005 生成的文件是UTF-8编码的,能不能更改成GB2312?
- 问一个C#能否容易实现的问题?
- 对于打DATASET中新增的一对记录,并将其存到数据库中,其记录状态是怎么变化的?
- 在VS里使用FreeTextBox HTML编辑器出现点问题!
- 如何实现这个功能?
- checkbox的问题
- 在vs2010服务器资源管理器添加数据库链接时出错
- 一个关于datagrid,iframe的问题,求教各位大虾!
- dlProList_EditCommand C#中不能捕获 VB.NET中能捕获, 这是怎么回事?
- button的click事件和command事件有什么区别啊?
搜索一下就能找到很多例子
http://dotnet.aspx.cc/ShowDetail.aspx?id=58EA3515-36F2-4FD9-AC89-EAF49F59816C
{
string path=this.Server.MapPath("../"+Session["diqu"].ToString()+"/"+Session["shixian"].ToString()+"/"+Session["username"].ToString()+"/image");
string filename="";
long filesize;
if(this.ff_tp.PostedFile.FileName.Trim()=="")
{
DataSet dst=new DataSet();
//ld.update((string)Session["czming"],this.txt_shuoming.Text,this.txt_neirong.Text,this.drop_shunxu.SelectedItem.Text,id,this.txt_shuoming2.Text);
gh.insert(Session["czming"].ToString(),this.txt_neirong.Text,this.txt_shuoming.Text,filename);
this.Response.Redirect("adminguihua.aspx");
}
else
{
try
{
filename=this.ff_tp.PostedFile.FileName.ToString();
string[] type=filename.Split('.');
string filetype = type[type.Length - 1];
filesize = this.ff_tp.PostedFile.ContentLength;
string fileName = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() +System.DateTime.Now.Second.ToString();
filename = fileName+"." + filetype;
HttpFileCollection MyFileColl = HttpContext.Current.Request.Files;
HttpPostedFile MyPostedFile = MyFileColl[0];
if (filesize> 204800)
{
this.lbl_error.Text="上传附件大小不能超过2MB!";
}
else
{
if(filetype == "gif" || filetype == "jpg")
{
DataSet dst=new DataSet();
this.GetThumbNail(filename,130,100,this.ff_tp.PostedFile.ContentType.ToString(),false,MyPostedFile.InputStream);
gh.insert(Session["czming"].ToString(),this.txt_neirong.Text,this.txt_shuoming.Text,filename);
this.Response.Redirect("adminguihua.aspx");
this.ff_tp.Value="";
}
else
this.lbl_error.Text="上传的附件只能是GIF、JPG格式的文件!";
}
}
catch(Exception er)
{
this.lbl_error.Text=er.Message;
}
}
[Visual Basic, C#, C++] 注意 此示例显示如何使用 UploadFile 的一个重载版本。有关其他可用示例,请参阅单独的重载主题。[C#]
Console.Write("\nPlease enter the URL to post data to : ");
String uriString = Console.ReadLine();// Create a new WebClient instance.
WebClient myWebClient = new WebClient();Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URL");
string fileName = Console.ReadLine();Console.WriteLine("Uploading {0} to {1} ...",fileName,uriString);
// Upload the file to the URL using the HTTP 1.0 POST.
byte[] responseArray = myWebClient.UploadFile(uriString,"POST",fileName);// Decode and display the response.
Console.WriteLine("\nResponse Received.The contents of the file uploaded are: \n{0}",Encoding.ASCII.GetString(responseArray));
{
if ((strContentType.ToString().ToLower()) == "image/pjpeg")
{
return System.Drawing.Imaging.ImageFormat.Jpeg;
}
else if ((strContentType.ToString().ToLower()) == "image/gif")
{
return System.Drawing.Imaging.ImageFormat.Gif;
}
else if ((strContentType.ToString().ToLower()) == "image/bmp")
{
return System.Drawing.Imaging.ImageFormat.Bmp;
}
else if ((strContentType.ToString().ToLower()) == "image/tiff")
{
return System.Drawing.Imaging.ImageFormat.Tiff;
}
else if ((strContentType.ToString().ToLower()) == "image/x-icon")
{
return System.Drawing.Imaging.ImageFormat.Icon;
}
else if ((strContentType.ToString().ToLower()) == "image/x-png")
{
return System.Drawing.Imaging.ImageFormat.Png;
}
else if ((strContentType.ToString().ToLower()) == "image/x-emf")
{
return System.Drawing.Imaging.ImageFormat.Emf;
}
else if ((strContentType.ToString().ToLower()) == "image/x-exif")
{
return System.Drawing.Imaging.ImageFormat.Exif;
}
else if ((strContentType.ToString().ToLower()) == "image/x-wmf")
{
return System.Drawing.Imaging.ImageFormat.Wmf;
}
else
{
return System.Drawing.Imaging.ImageFormat.MemoryBmp;
}
}
string strContentType, bool blnGetFromFile, System.IO.Stream ImgStream)
{
System.Drawing.Image oImg;
if (blnGetFromFile)
{
oImg = System.Drawing.Image.FromFile(strFileName);
}
else
{
oImg = System.Drawing.Image.FromStream(ImgStream);
}
oImg = oImg.GetThumbnailImage(iWidth, iheight, null, IntPtr.Zero);
string strGuid = System.Guid.NewGuid().ToString().ToUpper();
string strFileExt = strFileName.Substring(strFileName.LastIndexOf("."));
Response.ContentType = strContentType;
// MemoryStream MemStream = new MemoryStream();
string path=this.Server.MapPath("../"+Session["diqu"].ToString()+"/"+Session["shixian"].ToString()+"/"+Session["username"].ToString()+"/image/");
oImg.Save(path+strFileName);
// oImg.Save(MemStream, GetImageType(strContentType));
// MemStream.WriteTo(Response.OutputStream);
}
http://www.ondotnet.com/pub/a/dotnet/2002/04/01/asp.html
http://www.codeproject.com/aspnet/fileupload.asp
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemIO.htm
但是,如果是网站的空间的话,那还涉及到权限问题,要与网站的管理员商量