app.config文件的更新问题

byj2001329 2009-07-24 01:08:11
自己做了个自动更新程序,是通过把文件保存到sql数据库,再从客户端下载实现的。
现在其它文件没有问题,但exe.config文件更新后,启动程序文件说配置文件出错,把config配置文件用记事本打开,直接保存,就没有问题了。请问如何解决?
...全文
149 21 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanlongwuhui 2009-08-13
  • 打赏
  • 举报
回复
应该是编码问题,可以试试转成BASE64然后保存在数据库中,取的时候转换回来后再保存成文件
byj2001329 2009-08-13
  • 打赏
  • 举报
回复
再顶一次
xunis 2009-08-10
  • 打赏
  • 举报
回复
至此 我也认为编码的问题 这问题我只经历过编码不对 要么楼主好好检查检查 或请经验丰富的同事之类的看看 现实和网络看问题 毕竟有疏漏
byj2001329 2009-08-10
  • 打赏
  • 举报
回复
怎么没有实质性回复啊
SanDy_O 2009-08-04
  • 打赏
  • 举报
回复
...
appleller 2009-08-03
  • 打赏
  • 举报
回复
...
lxs25451413500 2009-08-03
  • 打赏
  • 举报
回复
...
byj2001329 2009-08-03
  • 打赏
  • 举报
回复
上面的第二部分贴错了,是这个
'读取字节流生成文件。
Public Shared Function ConverBytesToFile(ByVal RootPath As String, ByVal FileName As String, ByVal FileData As Byte(), ByVal encode As Encoding) As Boolean
Dim Result As Boolean
Dim s As Integer
Dim fs As FileStream = Nothing
Dim SubPath As String
Try
'todo建目前不存在的文件夹
s = FileName.LastIndexOf("\")
If s >= 0 Then

SubPath = RootPath & IIf(RootPath.EndsWith("\"), "", "\") & FileName.Substring(0, s) & "\"
FileName = FileName.Substring(s + 1)
If Not Directory.Exists(SubPath) Then
Directory.CreateDirectory(SubPath)
End If
Else
SubPath = RootPath & IIf(RootPath.EndsWith("\"), "", "\")
End If
If Not Directory.Exists(SubPath) Then
Directory.CreateDirectory(SubPath)
End If
fs = New FileStream(SubPath & FileName, FileMode.OpenOrCreate)
'fs.Write(FileData, 0, FileData.Length)
'fs.Flush()

Dim SwFromFileStreamDefaultEnc As BinaryWriter = New BinaryWriter(fs, encode)
SwFromFileStreamDefaultEnc.Write(FileData, 0, FileData.Length)
SwFromFileStreamDefaultEnc.Flush()
SwFromFileStreamDefaultEnc.Close()
Result = True
Catch ex As Exception
Result = False
'忽略错误
Finally
If Not fs Is Nothing Then
fs.Close()
End If
End Try
Return Result
End Function
byj2001329 2009-08-03
  • 打赏
  • 举报
回复
使用下面的方法转化文件,从msgbox可以知道是用什么编码来执行的,用了utf8和统一码都不行,还是得用记事本或其它文本编辑器打开保存下就可以了

'读取文件到字节流,失败则返回Nothing
Public Shared Function ConvertFileToBytes(ByVal FileName As String, ByVal encode As System.Text.Encoding) As Byte()
Dim Result() As Byte
Dim fs As FileStream
If File.Exists(FileName) Then
Try
MsgBox(FileName + " " + encode.ToString)
fs = New FileStream(FileName, FileMode.Open)
Result = New Byte(fs.Length) {}
Dim SwFromFileStreamDefaultEnc As BinaryReader = New BinaryReader(fs, encode)
SwFromFileStreamDefaultEnc.Read(Result, 0, fs.Length)
SwFromFileStreamDefaultEnc.Close()
Catch ex As Exception
Result = Nothing
End Try
Else
Result = Nothing
End If
Return Result
End Function

'读取字节流生成文件。
Public Shared Function ConverBytesToFile(ByVal RootPath As String, ByVal FileName As String, ByVal FileData As Byte()) As Boolean
Dim Result As Boolean
Dim s As Integer
Dim fs As FileStream = Nothing
Dim SubPath As String
Try
'todo建目前不存在的文件夹
s = FileName.LastIndexOf("\")
If s >= 0 Then

SubPath = RootPath & IIf(RootPath.EndsWith("\"), "", "\") & FileName.Substring(0, s) & "\"
FileName = FileName.Substring(s + 1)
If Not Directory.Exists(SubPath) Then
Directory.CreateDirectory(SubPath)
End If
Else
SubPath = RootPath & IIf(RootPath.EndsWith("\"), "", "\")
End If
If Not Directory.Exists(SubPath) Then
Directory.CreateDirectory(SubPath)
End If
fs = New FileStream(SubPath & FileName, FileMode.OpenOrCreate)

fs.Write(FileData, 0, FileData.Length)
fs.Flush()
Result = True
Catch ex As Exception
Result = False
'忽略错误
Finally
If Not fs Is Nothing Then
fs.Close()
End If
End Try
Return Result
End Function
jane_zhao 2009-07-30
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="utf-8" ?>
config文件第一句应该就是这句吧。
然后将你程序里编码也统一成utf8
System.Text.Encoding.UTF8
jack43349489 2009-07-30
  • 打赏
  • 举报
回复
编码 编码 !
oec2003 2009-07-27
  • 打赏
  • 举报
回复
统一编码格式
gongsun 2009-07-27
  • 打赏
  • 举报
回复
...
byj2001329 2009-07-24
  • 打赏
  • 举报
回复
我打开文件和保存时都判断了encoding,但还是不行
rocker0325 2009-07-24
  • 打赏
  • 举报
回复
编码格式不对吧。。
wuyq11 2009-07-24
  • 打赏
  • 举报
回复
应该是编码问题,更新exe.config时通过streamwriter使用UTF-8编码打开再保存
farwy 2009-07-24
  • 打赏
  • 举报
回复
记事本编码格式是ANSI编码,你看你的项目是什么编码。
chuying718 2009-07-24
  • 打赏
  • 举报
回复
路过
cpp2017 2009-07-24
  • 打赏
  • 举报
回复
保存的时候编码不对,
kkun_3yue3 2009-07-24
  • 打赏
  • 举报
回复
编码?

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧