如何将ftp服务器映像文件转换为bytearray。 [英] How do I convert ftp server image file into bytearray.

查看:117
本文介绍了如何将ftp服务器映像文件转换为bytearray。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,它是庞大的,并且不支持给定路径的错误,

这里str保存我的ftp文件路径。





salesid = cmbclient.SelectedValue

createdon = Today.Date.ToShortDateString

ReDim docimage(ob.ConvertImageToByteArray(str).Length )

docimage = ob.ConvertImageToByteArray(str)

createdby = UserName

filename = ListBox1.SelectedItem

srv .SaveInvoiceImage(salesid:= salesid,CB:= docimage,invoiceimage:= filename,createdon:= createdon,createdby:= createdby)

MsgBox(Image Approval Succedded,MsgBoxStyle.Information)





公共函数ConvertImageToByteArray(ByVal str As String)As Byte()

Dim fs As FileStream = New FileStream (str,FileMode.Open,FileAccess.Read)//错误通过这里

Dim length As Integer = Convert.ToInt32(fs.Length)
Dim data()As Byte = Nothing

ReDim数据(长度)

fs.Read(data,0,data.Length)

fs.Close()

返回数据



我尝试过:



我试过这个



salesid = cmbclient.SelectedValue

createdon = Today.Date.ToShortDateString

ReDim docimage(ob.ConvertImageToByteArray(str).Length)

docimage = ob.ConvertImageToByteArray(str)

createdby =用户名

filename = ListBox1.SelectedItem

srv.SaveInvoiceImage(salesid:= salesid,CB:= docimage,invoiceimage:= filename,createdon:= createdon,createdby:=已创建)

MsgBox(Image Approval Succedded,MsgBoxStyle.Information)





公共函数ConvertImageToByteArray( ByVal str As String)As Byte()

Dim fs As FileStream = N.通过这里ew FileStream(str,FileMode.Open,FileAccess.Read)错误

Dim length As Integer = Convert.ToInt32(fs.Length)

Dim data()As Byte = Nothing

ReDim数据(长度)

fs.Read(data,0,data.Length)

fs.Close()

返回数据

解决方案

我认为您不能直接使用带有FTP地址的FileStream。

你可能不得不使用FtpWebRequest:

FtpWebRequest类 [ ^ ]

如何:使用FTP下载文件 [ ^ ]

Here is my code which is thronging and error of the given is path is not supported,
here str holds my ftp file path.


salesid = cmbclient.SelectedValue
createdon = Today.Date.ToShortDateString
ReDim docimage(ob.ConvertImageToByteArray(str).Length)
docimage = ob.ConvertImageToByteArray(str)
createdby = UserName
filename = ListBox1.SelectedItem
srv.SaveInvoiceImage(salesid:=salesid, CB:=docimage, invoiceimage:=filename, createdon:=createdon, createdby:=createdby)
MsgBox("Image Approval Succedded", MsgBoxStyle.Information)


Public Function ConvertImageToByteArray(ByVal str As String) As Byte()
Dim fs As FileStream = New FileStream(str, FileMode.Open, FileAccess.Read)//error through here
Dim length As Integer = Convert.ToInt32(fs.Length)
Dim data() As Byte = Nothing
ReDim data(length)
fs.Read(data, 0, data.Length)
fs.Close()
Return data

What I have tried:

I have tried this

salesid = cmbclient.SelectedValue
createdon = Today.Date.ToShortDateString
ReDim docimage(ob.ConvertImageToByteArray(str).Length)
docimage = ob.ConvertImageToByteArray(str)
createdby = UserName
filename = ListBox1.SelectedItem
srv.SaveInvoiceImage(salesid:=salesid, CB:=docimage, invoiceimage:=filename, createdon:=createdon, createdby:=createdby)
MsgBox("Image Approval Succedded", MsgBoxStyle.Information)


Public Function ConvertImageToByteArray(ByVal str As String) As Byte()
Dim fs As FileStream = New FileStream(str, FileMode.Open, FileAccess.Read)error through here
Dim length As Integer = Convert.ToInt32(fs.Length)
Dim data() As Byte = Nothing
ReDim data(length)
fs.Read(data, 0, data.Length)
fs.Close()
Return data

解决方案

I don't think you can use a FileStream directly with a FTP address.
You may have to use a FtpWebRequest instead:
FtpWebRequest Class[^]
How to: Download Files with FTP[^]


这篇关于如何将ftp服务器映像文件转换为bytearray。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆