HttpFileCollection MyFileCollection;
MyFileCollection = Request.Files;
int FileLen;
System.IO.Stream MyStream;
HttpPostedFile MyFile;
MyFile=MyFileCollection.Get(0);
FileLen = MyFile.ContentLength;str=MyFile.FileName.ToString().Split( new char[] {'.'});
if (str[str.Length-1].ToUpper()!="JPG" && str[str.Length-1].ToUpper()!="JPGE" && str[str.Length-1].ToUpper()!="BMP" && str[str.Length-1].ToUpper()!="GIF")
{
alertmsg("选择的文件类型不正确,只支持*.jpg,*.jpge,*.bmp,*.gif格式的文件上传!");
}
MyFileCollection = Request.Files;
int FileLen;
System.IO.Stream MyStream;
HttpPostedFile MyFile;
MyFile=MyFileCollection.Get(0);
FileLen = MyFile.ContentLength;str=MyFile.FileName.ToString().Split( new char[] {'.'});
if (str[str.Length-1].ToUpper()!="JPG" && str[str.Length-1].ToUpper()!="JPGE" && str[str.Length-1].ToUpper()!="BMP" && str[str.Length-1].ToUpper()!="GIF")
{
alertmsg("选择的文件类型不正确,只支持*.jpg,*.jpge,*.bmp,*.gif格式的文件上传!");
}
解决方案 »
- 遍历赋值!
- [开源与分享]自己写的一个操作数据表的小组件,个人用着觉得很爽,希望大家喜欢
- 程序本地调试通过,发布在IIS上,按钮点击事件异常,事件代码:4011
- ASP.NET(C#)中,用GridView输出到EXCEL,但是老是在保存完excel文件后,再打开时有错!
- gridview输出excel ,如何指定路径,急?
- 超级菜鸟问题?ASP.net中怎么调用javascript
- 请问类似这样的链接--http://www.58.com/Web/PostInfo.aspx?821,0,0,2,31,276367--如何读取它的值?
- 思归、孟子等高手帮我看看这个问题,我发过好多篇了有关Reporting Service方面的。
- 封装页面的问题
- ===== 一个提示窗口,或者是对话框。怎么写?======
- 将数据库里的数据读到xml文件里再转化成word文档,有啥好办法?
- 索取kaersoft论坛源代码
HttpFileCollection MyFileCollection;
MyFileCollection = Request.Files;
int FileLen;
System.IO.Stream MyStream;
HttpPostedFile MyFile;
MyFile=MyFileCollection.Get(0);
FileLen = MyFile.ContentLength;
//判断是否选择了附件
if (FileLen==0)
{
alertmsg("请选择要上传的照片!");
}
else if(FileLen/1024>2000)
{
//判断附件是否超大
alertmsg("选择的照片超过限定大小,只允许上传2M以下的附件!");
}
else
{
String[] str;
str=MyFile.FileName.ToString().Split( new char[] {'.'});
if (str[str.Length-1].ToUpper()!="JPG" && str[str.Length-1].ToUpper()!="JPGE" && str[str.Length-1].ToUpper()!="BMP" && str[str.Length-1].ToUpper()!="GIF")
{
alertmsg("选择的文件类型不正确,只支持*.jpg,*.jpge,*.bmp,*.gif格式的文件上传!");
}
else
{
int OldW,OldH;
OldW=(int)System.Convert.ToDouble(txtw.Value.ToString().Trim());
OldH=(int)System.Convert.ToDouble(txth.Value.ToString().Trim());
this.lblw.Text=OldW.ToString();
this.lblh.Text =OldH.ToString();
MyStream = MyFile.InputStream;
Byte[] Input=new byte[FileLen];
String filetype;
filetype = MyFile.ContentType;
MyStream.Read(Input, 0, FileLen);
SqlConnection Conn=new SqlConnection(Application["connstr"].ToString());
Conn.Open();
SqlCommand comm=new SqlCommand(); comm.Connection=Conn;
comm.CommandText = "update 员工基础信息 set 照片=@Bmp, 照片文件类型=@type,照片大小='" + FileLen + "',照片宽='" + this.lblw.Text + "',照片高='" + this.lblh.Text + "' where id=" + Request["empid"].ToString();
comm.Parameters.Add("@Bmp", SqlDbType.Binary,FileLen).Value =Input;
comm.Parameters.Add("@type", SqlDbType.NVarChar).Value = filetype;
comm.ExecuteNonQuery();
Conn.Close(); }
}
}
}
这下你满足了吧?
MyFileCollection = Request.Files
Dim FileLen As Integer
Dim MyStream As System.IO.Stream
Dim MyFile As HttpPostedFile
MyFile = MyFileCollection.Get(0)
FileLen = MyFile.ContentLength
'判断是否选择了附件
If FileLen = 0 Then ' alertmsg("请选择要上传的照片!") ElseIf FileLen / 1024 > 2000 Then '判断附件是否超大
'alertmsg("选择的照片超过限定大小,只允许上传2M以下的附件!") Else Dim str() As String
str = Split(MyFile.FileName, ".")
If UCase(str(str.Length - 1)) <> "JPG" And UCase(str(str.Length - 1)) <> "JPGE" And UCase(str(str.Length - 1)) <> "BMP" And UCase(str(str.Length - 1)) <> "GIF" Then 'alertmsg("选择的文件类型不正确,只支持*.jpg,*.jpge,*.bmp,*.gif格式的文件上传!") Else Dim OldW, OldH As Integer
OldW = txtw.Value
OldH = txth.Value
lblw.Text = OldW
lblh.Text = OldH
MyStream = MyFile.InputStream
Dim Input() As Byte
Dim filetype As String
filetype = MyFile.ContentType
MyStream.Read(Input, 0, FileLen)
Dim Conn As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(Application("connstr"))
Conn.Open()
Dim comm As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand()
comm.Connection = Conn
comm.CommandText = "update 员工基础信息 set 照片=@Bmp, 照片文件类型=@type,照片大小='" + FileLen + "',照片宽='" + lblw.Text + "',照片高='" + lblh.Text + "' where id=" + Request("empid").ToString()
comm.Parameters.Add("@Bmp", SqlDbType.Binary, FileLen).Value = Input
comm.Parameters.Add("@type", SqlDbType.NVarChar).Value = filetype
comm.ExecuteNonQuery()
Conn.Close()
End If
End If
下面是我寫的代碼,供大家參考: If Page.IsPostBack Then
Dim MyFileCollection As HttpFileCollection
MyFileCollection = Request.Files
Dim FileLen As Integer
Dim MyStream As System.IO.Stream
Dim MyFile As HttpPostedFile
MyFile = MyFileCollection.Get(0)
FileLen = MyFile.ContentLength
If FileLen = 0 Then
WinFormsToWeb_MessageBox.Show("請選擇圖片文件", "更新失敗")
Else
If FileLen / 1024 > 20000 Then
WinFormsToWeb_MessageBox.Show("圖片文件過大", "更新失敗")
Else
Dim str() As String
str = Split(MyFile.FileName, ".")
If UCase(str(str.Length - 1)) <> "JPG" Then
WinFormsToWeb_MessageBox.Show("請選擇.jpg格式的圖片", "更新失敗")
Else
Dim MyString As String
MyFileCollection = Request.Files
MyFile = MyFileCollection(0)
FileLen = MyFile.ContentLength
Dim Input(FileLen) As Byte
MyStream = MyFile.InputStream
MyStream.Read(Input, 0, FileLen)
Dim Conn As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(PublicConnectString)
Conn.Open()
Dim comm As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand()
comm.Connection = Conn
comm.CommandText = "Update ObjectList set imageS = @ProductImage where id='" & Session("ImageSetup_Id") & "'"
comm.Parameters.Add("@ProductImage", SqlDbType.Binary, FileLen).Value = Input
comm.ExecuteNonQuery()
Conn.Close()
End If
End If
End If
End If