Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

如何將檔案轉為Byte陣列??

4 views
Skip to first unread message

阿德

unread,
Dec 20, 2006, 11:34:01 PM12/20/06
to
請教專家們
我要使用下列Web Service來傳送檔案,要如何將檔案匯入並轉為Byte陣列才能用此WS呢?
<WebMethod()> _
Public Function UploadFile(ByVal fs() As Byte, ByVal FileName As String)
As String
Dim m As New System.IO.MemoryStream(fs)
Dim f As New System.IO.FileStream(Server.MapPath(".") + "\" +
FileName, System.IO.FileMode.Create)
Try
m.WriteTo(f)
m.Close()
f.Close()
f = Nothing
m = Nothing
Return "success !"
Catch ex As Exception
Return ex.Message
End Try

End Function



璉璉

unread,
Dec 21, 2006, 3:13:29 AM12/21/06
to
http://tlcheng.twbbs.org/TLCheng/Net/NetList.aspx?Action=Function&Module=16&Function=94

==> 本文由 "阿德 <@discussions.microsoft.com>"
> 於 news:5927B554-2278-471B-A770-C75729CCAAC9%40microsoft.com 發表

--
風禹科技驗證有限公司 ASP.NET Web News Reader 0.2.5 UTF-8 Beta
網站地圖 http://tlcheng.twbbs.org/wwwmap.htm
流域防洪/區域水資源/徐昇網/玫瑰圖/語音通訊 文章與程式
Basic/Fortran/Windows API/.Net/輔助說明檔 原始碼、文章與討論
微軟程式設計、系統管理使用新技術論壇討論區,網友回覆後即時簡訊、電子郵件通知:
MSDN: http://forums.microsoft.com/msdn-cht/default.aspx?siteid=14
TechNet: http://forums.microsoft.com/technet-cht/default.aspx?siteid=23
--
ASPNET News Reader http://tlcheng.twbbs.org/News/Reader.aspx
RSS 2.0 http://tlcheng.twbbs.org/News/rss2.aspx?Action=List&Newsgroup=microsoft.public.tw.dotnet.framework.webservices

阿德

unread,
Dec 26, 2006, 2:57:00 AM12/26/06
to
請教璉璉大大:

我參考您所提供 module code
可是都會碰到一個問題

c:\inetpub\wwwroot\cgd2\modFileTool.vb(33): 名稱 'Application' 未宣告。
依您的經驗要如何去定義這Application呢?

Public Function MyGetAppPath() As String
Return Application.StartupPath
End Function

"璉璉" 來函:

璉璉

unread,
Dec 26, 2006, 9:36:04 AM12/26/06
to
你把整個 function 殺掉吧
這個是給 Windows Form 用的,在 ASP.NET 內沒有 (Web Service 也算是 ASP.NET)

==> 本文由 "阿德 <@discussions.microsoft.com>"
> 於 news:55E32FDF-49BB-45F1-9F5E-E7235EEEB042%40microsoft.com 發表

阿德

unread,
Dec 26, 2006, 7:43:00 PM12/26/06
to

1. 您指的是單獨MyGetAppPath() Function,還是指所有呼叫MyGetAppPath() Function皆殺掉呢?
2. 此Module code 可否供 Web Form來使用呢?
謝謝


"璉璉" 來函:

璉璉

unread,
Dec 26, 2006, 8:03:22 PM12/26/06
to
把所有有呼叫 MyGetAppPath 都殺掉即可。

你的應用中不需要使用到此部份。

可以。但是 Web Form 內沒有 Application 物件,所以這部份需要刪除。

==> 本文由 "阿德 <@discussions.microsoft.com>"
> 於 news:C6744643-F0B8-4671-A57F-667C7C974E28%40microsoft.com 發表

阿德

unread,
Dec 28, 2006, 9:46:00 PM12/28/06
to
我試過可利用您所提供 Module code來呼叫 WS 傳送檔案
不過傳送檔案大小最大只到3M.....
若想要調整檔案容量到 10M 以上是否可行?

"璉璉" 來函:

璉璉

unread,
Dec 29, 2006, 3:13:45 AM12/29/06
to
你看看這篇吧:
http://forums.microsoft.com/msdn-cht/ShowPost.aspx?PostID=791410&SiteID=14

你如果大型檔案持續輸出,建議你回到 ASP.NET 用 Response.WriteFile 輸出。

註:位元陣列會採用 Base64 壓縮, 3 bytes 變成 4 bytes ,所以 3 MB 變成 4 MB 。

==> 本文由 "阿德 <@discussions.microsoft.com>"
> 於 news:A8A44DCD-4B5A-41D6-B4FC-1AF4957FB1B4%40microsoft.com 發表

0 new messages