你的数据库是什么。
sqlser2000与oracle不同的
sqlser2000与oracle不同的
解决方案 »
- .net 新闻滚动
- 正则表达式--手机号码验证。
- TreeView 获取数据表
- 求助,checkbox问题
- 在GridView1_SelectedIndexChanging 事件中写修改数据 想用户点击修改数据时候弹出消息框 说明系统提示是否修改
- asp.net开发环境搭建问题
- 程序员们进来帮我看看!
- 请教,asp.net1.1中弹出消息框不闪屏如何思想。
- 一个关于IIS的问题,不知道怎么就出问题了,搞了N久急死了,大家都看下,放100分!
- 很有点难度,高手请进来看一下,关于在C/S中,Internet环境下,服务端如何传递消息给客户端?
- 求购网站和电子政务!!!!
- 高手请近:想在界面的DATAGRID表格里添加一个可以播放midi音乐的插件
<tr><td class="tableTop" vAlign="bottom" align="middle" background="image/topbg_table.gif" height="20">
<INPUT id="upfile" style="WIDTH: 444px; HEIGHT: 22px; BACKGROUND-COLOR: gainsboro" type="file" size="54" runat="server" NAME="upfile">
<asp:button id="Button_up" runat="server" Width="74px" Text="上传"></asp:button>
</td>
</tr>
然后,在按钮click事件里面
private void Button_up_Click(object sender, System.EventArgs e)
{
if(this.upfile.PostedFile!=null)
{
string FileName=this.upfile.PostedFile.FileName;
int num=FileName.LastIndexOf('\\');
if(num>=0&&FileName.Length-num-1>0)
{
FileName=FileName.Substring(num+1,FileName.Length-num-1);
}
else{
return;
}
string FileType=this.upfile.PostedFile.ContentType;
System.IO.Stream fs=this.upfile.PostedFile.InputStream;
Byte[] b=new Byte[fs.Length];
fs.Read(b,0,b.Length);
fs.Close();
string path=Server.MapPath("")+"\\myFile\\"+FileName;
FileStream fileStream=new FileStream(path,FileMode.Create,FileAccess.Write);
fileStream.Read(b,0,b.Length);
fileStream.Flush();
}
Imports System.IOPublic Class ClassFile Inherits System.Web.UI.Page Public FileName As String = "file_name"
Public FileNameNew As String = "file_name_new"
Public FilePath As String = "file_path"
Public FileSize As String = "file_size"
Public FileType As String = "file_type"
Public drFileInfo As DataRow ' 功能:得到上传文件的基本信息
Public Function GetFileInfo(ByVal HtmlInputFile As HtmlInputFile, ByVal FolderForSaveFile As String) As Boolean Dim strFolder As String ' 文件要保存的文件夹名称
Dim strFilePath As String ' 文件路径
Dim strFileName As String ' 文件上传前的名称
Dim strFileNameNew As String ' 文件上传后存储到硬盘的名称
Dim arrFileName() As String ' 分离文件名称的数组
Dim strFileType As String ' 文件类型
Dim arrFileType() As String ' 分离文件类型的数组
Dim lngFileSize As Long ' 文件大小 Dim strAttachNamePre As String ' 保存后的文件名前缀
Dim strAttachNameSuf As String ' 保存后的文件名后缀
Dim strAttachPathRel As String ' 保存后的文件相对路径 Dim intCount As Integer ' 循环计数器
Dim dtFileInfo As New DataTable() dtFileInfo.Columns.Add(New DataColumn(FileName, GetType(String)))
dtFileInfo.Columns.Add(New DataColumn(FileNameNew, GetType(String)))
dtFileInfo.Columns.Add(New DataColumn(FilePath, GetType(String)))
dtFileInfo.Columns.Add(New DataColumn(FileSize, GetType(Long)))
dtFileInfo.Columns.Add(New DataColumn(FileType, GetType(String))) If Not (HtmlInputFile.PostedFile Is Nothing) Then HtmlInputFile.Visible = True
' 上传的文件不能大于10MB
If HtmlInputFile.PostedFile.ContentLength() > 10 * (1024 * 1024) Then End If
strFilePath = HtmlInputFile.PostedFile.FileName()
If strFilePath = "" Then
Return False
Else
strFilePath = Replace(strFilePath, "/", "\")
strFilePath = Replace(strFilePath, "//", "\")
strFilePath = Replace(strFilePath, "\\", "\")
End If
'取得上传的文件名
For intCount = Len(strFilePath) To 1 Step -1
If Mid(strFilePath, intCount, 1) = "\" Then
strFileName = Right(strFilePath, Len(strFilePath) - intCount)
Exit For
End If
Next
'文件类型
strFileType = HtmlInputFile.PostedFile.ContentType()
'文件大小
lngFileSize = HtmlInputFile.PostedFile.ContentLength()
If lngFileSize <= 0 Then
Return False
End If
'取当前时刻作为保存后的文件名前缀
strAttachNamePre = Year(Now()) & Month(Now()) & Day(Now()) & Hour(Now()) & Minute(Now()) & Second(Now()) & HtmlInputFile.ID
'取得文件名后缀
arrFileName = Split(strFileName, ".")
intCount = UBound(arrFileName)
If intCount < 1 Then
strAttachNameSuf = ""
Else
strAttachNameSuf = "." & arrFileName(intCount)
End If
If strAttachNameSuf = "" Then
Return False
End If
' 文件名
strFileNameNew = strAttachNamePre & strAttachNameSuf
' 对文件夹进行处理
strFolder = FolderForSaveFile If Right(strFolder, 2) = "//" Then
strFolder = Left(strFolder, Len(strFolder) - 2)
ElseIf Right(strFolder, 1) = "/" Then
strFolder = Left(strFolder, Len(strFolder) - 1)
ElseIf Right(strFolder, 2) = "\\" Then
strFolder = Left(strFolder, Len(strFolder) - 2)
ElseIf Right(strFolder, 1) = "\" Then
strFolder = Left(strFolder, Len(strFolder) - 1)
End If
Me.GetFolderPathAbs(strFolder)
' 文件相对路径
strAttachPathRel = strFolder & "/" & strFileNameNew drFileInfo = dtFileInfo.NewRow
drFileInfo(FileName) = strFileName
drFileInfo(FileNameNew) = strFileNameNew
drFileInfo(FilePath) = strAttachPathRel
drFileInfo(FileSize) = lngFileSize
drFileInfo(FileType) = strFileType
dtFileInfo.Rows.Add(drFileInfo)
Return True
Else
Return False
End If End Function
End Class这里得到上传文件的类,参数为:控件名与文件保存路径
返回值:false没有文件上传;true有并可得到文件的一些信息