下面的这个Class是我以前用来传文件的,Upload.asp是用来接受的 好用别忘了给分,呵呵*******************************VB Class************************************ '-------------------------------------------------------------- ' Note: ' The XML format used in this class is ' <root> ' <file> ' <filename> ' </filename> ' <fileContent> ' </fileContent> ' </file> ' ...... ' ...... ' </root> ' one XML can contain several file '-------------------------------------------------------------- Option Explicit Dim XMLhttp As MSXML2.XMLHTTP30 Dim XMLDoc As MSXML2.DOMDocument30 Dim WebURL As String Dim XMLRootNode As VariantPrivate Sub Class_Initialize() Set XMLhttp = New MSXML2.XMLHTTP30 Set XMLDoc = New MSXML2.DOMDocument30 End SubPublic Sub Initialize() XMLDoc.loadXML "<root/>" Set XMLRootNode = XMLDoc.documentElement End SubPublic Property Let SetWebURL(URL As String) WebURL = URL End PropertyPublic Sub AddaFile(filaPath As String, fileName As String) Dim fileNum As Integer Dim btArr() As Byte Dim fileNameNode, fileContentNode, fileNode Set fileNode = XMLDoc.createNode(1, "file", "") XMLRootNode.appendChild (fileNode)
Set fileContentNode = XMLDoc.createNode(1, "fileContent", "") fileNode.appendChild (fileContentNode)
fileNum = FreeFile Open filaPath & fileName For Binary Access Read As #fileNum
ReDim btArr(LOF(fileNum)) Get #fileNum, , btArr() Close #fileNum
With fileContentNode .dataType = "bin.base64" .nodeTypedValue = btArr '如果要把需要传的字符串用Base64编码,这样处理 'Dim b() as byte 'b = "需要传的字符串" '.nodeTypedValue = b End With End SubPublic Function HttpUpload() As Boolean Dim strHeaders As String HttpUpload = False XMLhttp.open "POST", WebURL, False XMLhttp.send XMLDoc Debug.Print XMLhttp.responseText If XMLhttp.responseText = "Upload successful!" Then HttpUpload = True End If End FunctionPrivate Sub Class_Terminate() Set XMLhttp = Nothing Set XMLDoc = Nothing End Sub*******************************ASP (Upload.asp)******************************** <%@ LANGUAGE=VBScript%> <% Option Explicit Response.Expires = 0 dim ado_stream dim xml_dom Dim i Dim UpPath dim CurrentFileName Dim oNodelist Dim currNode'注意:这个文件夹一定要存在的 UpPath = replace(Server.MapPath("Upload.asp"),"Upload.asp","UPfiles\")set ado_stream = Server.CreateObject("ADODB.Stream") set xml_dom = Server.CreateObject("MSXML2.DOMDocument") xml_dom.load(request) Set oNodelist = xml_dom.selectNodes("/root/file") For i = 0 To oNodelist.length - 1 Set currNode = oNodelist.Item(i).selectSingleNode("filename") CurrentFileName = currNode.Text Set currNode = oNodelist.Item(i).selectSingleNode("fileContent") ado_stream.Type = 1 ' 1=adTypeBinary ado_stream.open ado_stream.Write currNode.nodeTypedValue ado_stream.SaveToFile UpPath & CurrentFileName,2 ' 2=adSaveCreateOverWrite ado_stream.close Next set ado_stream = Nothing set xml_dom = Nothing Response.Write "Upload successful!" %>
太感激了,你稍等,先50分记帐上,等我全部测试好了,另外再給50。 还有,其实我要做的是同步更新问题,除了上传,我还需要对网络上已经更新的数据下载到本地数据库,这样就完整了。嗨,想法到是很多个,做起来麻烦事多,方法不对,一入手就碰到乱骂问题,卡卡卡,还好ouyi兄的帮助, Thank you very much! Thank you very much! Thank you very much!
问题在我传上去之后,有些字出得来,有些字就出不来,哪位大哥帮忙也试一下;是不是VB得问题啊?
我要做的操作流程是通过客户端用VB的winsock上传字符串(或上传文件)
写入Internet上的数据库,乱乱乱码。
VB的winsock传输unicode字符串的时候会自动传为ANSI编码,那在另外一端应该怎样写,才能转为正确的unicode字符。这样我是否用文件传输的方式来做,ouyi0901兄,再帮忙一把,100分就給你了
建议你把要传的字符串(或文件)先用Base64编码,然后再传,接受端解码后再保存肯定没问题
[email protected]
'--------------------------------------------------------------
' Note:
' The XML format used in this class is
' <root>
' <file>
' <filename>
' </filename>
' <fileContent>
' </fileContent>
' </file>
' ......
' ......
' </root>
' one XML can contain several file
'--------------------------------------------------------------
Option Explicit
Dim XMLhttp As MSXML2.XMLHTTP30
Dim XMLDoc As MSXML2.DOMDocument30
Dim WebURL As String
Dim XMLRootNode As VariantPrivate Sub Class_Initialize()
Set XMLhttp = New MSXML2.XMLHTTP30
Set XMLDoc = New MSXML2.DOMDocument30
End SubPublic Sub Initialize()
XMLDoc.loadXML "<root/>"
Set XMLRootNode = XMLDoc.documentElement
End SubPublic Property Let SetWebURL(URL As String)
WebURL = URL
End PropertyPublic Sub AddaFile(filaPath As String, fileName As String)
Dim fileNum As Integer
Dim btArr() As Byte
Dim fileNameNode, fileContentNode, fileNode Set fileNode = XMLDoc.createNode(1, "file", "")
XMLRootNode.appendChild (fileNode)
Set fileNameNode = XMLDoc.createNode(1, "filename", "")
fileNameNode.Text = fileName
fileNode.appendChild (fileNameNode)
Set fileContentNode = XMLDoc.createNode(1, "fileContent", "")
fileNode.appendChild (fileContentNode)
fileNum = FreeFile
Open filaPath & fileName For Binary Access Read As #fileNum
ReDim btArr(LOF(fileNum))
Get #fileNum, , btArr()
Close #fileNum
With fileContentNode
.dataType = "bin.base64"
.nodeTypedValue = btArr
'如果要把需要传的字符串用Base64编码,这样处理
'Dim b() as byte
'b = "需要传的字符串"
'.nodeTypedValue = b
End With
End SubPublic Function HttpUpload() As Boolean
Dim strHeaders As String
HttpUpload = False
XMLhttp.open "POST", WebURL, False
XMLhttp.send XMLDoc Debug.Print XMLhttp.responseText
If XMLhttp.responseText = "Upload successful!" Then
HttpUpload = True
End If
End FunctionPrivate Sub Class_Terminate()
Set XMLhttp = Nothing
Set XMLDoc = Nothing
End Sub*******************************ASP (Upload.asp)********************************
<%@ LANGUAGE=VBScript%>
<% Option Explicit
Response.Expires = 0 dim ado_stream
dim xml_dom
Dim i
Dim UpPath
dim CurrentFileName
Dim oNodelist
Dim currNode'注意:这个文件夹一定要存在的
UpPath = replace(Server.MapPath("Upload.asp"),"Upload.asp","UPfiles\")set ado_stream = Server.CreateObject("ADODB.Stream")
set xml_dom = Server.CreateObject("MSXML2.DOMDocument")
xml_dom.load(request)
Set oNodelist = xml_dom.selectNodes("/root/file")
For i = 0 To oNodelist.length - 1
Set currNode = oNodelist.Item(i).selectSingleNode("filename")
CurrentFileName = currNode.Text Set currNode = oNodelist.Item(i).selectSingleNode("fileContent")
ado_stream.Type = 1 ' 1=adTypeBinary
ado_stream.open ado_stream.Write currNode.nodeTypedValue
ado_stream.SaveToFile UpPath & CurrentFileName,2 ' 2=adSaveCreateOverWrite
ado_stream.close
Next
set ado_stream = Nothing
set xml_dom = Nothing
Response.Write "Upload successful!"
%>
还有,其实我要做的是同步更新问题,除了上传,我还需要对网络上已经更新的数据下载到本地数据库,这样就完整了。嗨,想法到是很多个,做起来麻烦事多,方法不对,一入手就碰到乱骂问题,卡卡卡,还好ouyi兄的帮助,
Thank you very much!
Thank you very much!
Thank you very much!
论坛上回答了好几个和你类是得问题了。XML功能很强大的,同步更新都可以用得上,可以将网络数据库的信息用ASP之类的东东生成一个XML文档,可能遇到乱码的用Base64或其他方式先编码,客户端只要用XML_DOC.Load("")这个asp文件就可以了,然后进行后面的处理,这个方法我在项目中用过,很方便的,你可以参考参考,存数据库时用Unicode可以避免英文平台不支持其它文字的问题。
遇到问题我会尽力解决,
还有多多有劳指教。
我也会把做出来的东西让大家一起来分享(现在没有哦)的
.............CSDN人气真旺,
此处杀气腾腾,高手隐没。
小心,接招