using System.Text; file_name = filename.text Dim strwriterobj As StreamWriter = File.CreateText ( file_name, false,Encoding.GetEncoding("GB2312")) Dim contxt as String contxt = body.text ' 其中body.text是要写入文件的内容 ' 创建一个文件,并把此文本文件作为对象分派给 streamwriter对象 strwriterobj.WriteLine( contxt ) ' 把文本内容写入文件中 strwriterobj.Close '关闭对象 写入后的文件123.htm中文显示成了烂码?!~!!!
Dim strwriterobj As StreamWriter = File.CreateText ( file_name, false,Encoding.GetEncoding("GB2312")) 运行后BC30057: “Public Shared Function CreateText(path As String) As System.IO.StreamWriter”的参数太多。
Dim strwriterobj As StreamWriter dim fs as FileStream Dim contxt as String file_name = filename.text contxt = body.text ' 其中body.text是要写入文件的内容 fs = File.Create( file_name ) strwriterobj=new StreamWriter(fs,Encoding.GetEncoding("GB2312")) ' 创建一个文件,并把此文本文件作为对象分派给 streamwriter对象 strwriterobj.WriteLine( contxt ) ' 把文本内容写入文件中 fs.close strwriterobj.Close '关闭对象 写入后的文件123.htm中文显示成了烂码?!~!!!
我使用的上传代码,你可参考试试<Script Language="VB" Runat="Server"> Sub Upload(sender As Object, e As Eventargs)
Dim StoredString,LinkString As String Dim Myconn As SQLconnection Dim Mycommand As SQLcommand
If myFile.PostedFile.ContentLength = 0 or myFile.PostedFile.ContentLength > 10*1024*1024 Then Result.Text = "上传失败!指定的文件不存在或文件大小超过10M !" FileInfo.Visible = False Else '获取文件名称 Dim Route() As String = Split(myFile.PostedFile.FileName, "\") Dim FileName As String = Route(Route.Length - 1) If kemu.value ="" then kemu.value = FileName end if if shuoming.value = "" then shuoming.value = FileName end if '写数据库记录 Myconn = Com_ConnOpen LinkString = "http://*********" & FileName MyCommand = New SQLCommand("InsertDownloadInformation",Myconn) MyCommand.CommandType = CommandType.StoredProcedure Mycommand.Parameters.Add("@UserID",Session("UserID")) Mycommand.Parameters.Add("@UserName",Session("UserName")) Mycommand.Parameters.Add("@FilesName",FileName) Mycommand.Parameters.Add("@Link",LinkString) Mycommand.Parameters.Add("@FilesSize",Math.Round(myFile.PostedFile.ContentLength /( 1024*1024 ), 2)) Mycommand.Parameters.Add("@instruction",shuoming.value) Mycommand.Parameters.Add("@topic",kemu.value) '执行写库表操作 MyCommand.ExecuteNonquery() '关闭数据库连接 MyConn.Close()
'保存文件 myFile.PostedFile.SaveAs(Server.MapPath("******") & "\" & FileName) '显示上传结果 FileInfo.Visible = True Result.Text = "上传成功" FName.Text = FileName FSize.Text = Math.Round(myFile.PostedFile.ContentLength / 1024, 2) & "KB" FType.Text = myFile.PostedFile.ContentType End If End Sub </Script>
GetEncoding怎么用上去!
strwriterobj = File.CreateText ( file_name )???继续关注
Dim strwriterobj As StreamWriter = File.CreateText ( file_name, false,Encoding.GetEncoding("GB2312")) Dim contxt as String contxt = body.text
' 其中body.text是要写入文件的内容
' 创建一个文件,并把此文本文件作为对象分派给 streamwriter对象
strwriterobj.WriteLine( contxt )
' 把文本内容写入文件中
strwriterobj.Close
'关闭对象
写入后的文件123.htm中文显示成了烂码?!~!!!
dim fs as FileStream
Dim contxt as String
file_name = filename.text
contxt = body.text
' 其中body.text是要写入文件的内容
fs = File.Create( file_name )
strwriterobj=new StreamWriter(fs,Encoding.GetEncoding("GB2312"))
' 创建一个文件,并把此文本文件作为对象分派给 streamwriter对象
strwriterobj.WriteLine( contxt )
' 把文本内容写入文件中
fs.close
strwriterobj.Close
'关闭对象
写入后的文件123.htm中文显示成了烂码?!~!!!
Sub Upload(sender As Object, e As Eventargs)
Dim StoredString,LinkString As String
Dim Myconn As SQLconnection
Dim Mycommand As SQLcommand
If myFile.PostedFile.ContentLength = 0 or myFile.PostedFile.ContentLength > 10*1024*1024 Then
Result.Text = "上传失败!指定的文件不存在或文件大小超过10M !"
FileInfo.Visible = False
Else
'获取文件名称
Dim Route() As String = Split(myFile.PostedFile.FileName, "\")
Dim FileName As String = Route(Route.Length - 1)
If kemu.value ="" then
kemu.value = FileName
end if
if shuoming.value = "" then
shuoming.value = FileName
end if '写数据库记录
Myconn = Com_ConnOpen
LinkString = "http://*********" & FileName
MyCommand = New SQLCommand("InsertDownloadInformation",Myconn)
MyCommand.CommandType = CommandType.StoredProcedure
Mycommand.Parameters.Add("@UserID",Session("UserID"))
Mycommand.Parameters.Add("@UserName",Session("UserName"))
Mycommand.Parameters.Add("@FilesName",FileName)
Mycommand.Parameters.Add("@Link",LinkString)
Mycommand.Parameters.Add("@FilesSize",Math.Round(myFile.PostedFile.ContentLength /( 1024*1024 ), 2))
Mycommand.Parameters.Add("@instruction",shuoming.value)
Mycommand.Parameters.Add("@topic",kemu.value)
'执行写库表操作
MyCommand.ExecuteNonquery()
'关闭数据库连接
MyConn.Close()
'保存文件
myFile.PostedFile.SaveAs(Server.MapPath("******") & "\" & FileName)
'显示上传结果
FileInfo.Visible = True
Result.Text = "上传成功"
FName.Text = FileName
FSize.Text = Math.Round(myFile.PostedFile.ContentLength / 1024, 2) & "KB"
FType.Text = myFile.PostedFile.ContentType
End If
End Sub
</Script>
这句话有问题,改为Encoding的其它枚举类型,我记得用UTF7或UTF8就可以搞定