silverlight 如何写入指定目录下的文件

 我来答
Dwain_Li
推荐于2016-11-06 · 超过20用户采纳过TA的回答
知道答主
回答量:62
采纳率:0%
帮助的人:45.7万
展开全部
不明白你是想怎么写,两种情况:
1.已有文件源或者stream,采用楼上方法试试;
2.比较好的方法:出于安全性考虑,客户端是不能直接读取或者写文件的,你可以通过webservice对指定文件流写入指定文件,贴一个webservice类似的方法:
首先客户端获取打开文件(VB代码):
Dim dialog = New OpenFileDialog() With { _
.Multiselect = False, _
.Filter = "All Files (*.*)|*.*"
}
If dialog.ShowDialog() = True Then
If dialog.Files IsNot Nothing Then
Dim f As FileInfo = dialog.File
_fileSteam = f.OpenRead
filename = f.ToString
yichang.AttachFileName = filename
Me.txtAttachFileName.Text = f.ToString
Else
End If
End If
服务端
<WebMethod()> _
Public Function UpLoadAttachFile(ByVal FileByte As Byte(), ByVal offSet As Long, ByVal AttachFileName As String, ByVal AttachReFileName As String) As String
Dim _fileOperatorPath As String = Server.MapPath("FilesPath/")
Dim _attachfilename As String = ""
If AttachReFileName <> "" Then
_attachfilename = AttachReFileName
Else
'获取文件后缀
Dim _filter As String = AttachFileName.ToString.Substring(AttachFileName.ToString.LastIndexOf("."))
'重命名文件
_attachfilename = Convert.ToDateTime(Now.ToString.Replace("/", "-")).ToString("yyyyMMddHHmmss") & _filter
End If
Dim _AttachFileSavePath As String = _fileOperatorPath & _attachfilename
Try
Dim buffer As Byte() = FileByte
If buffer IsNot Nothing Then
'读写文件的文件流,支持同步读写也支持异步读写
Dim filesStream As New FileStream(_AttachFileSavePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)
filesStream.Seek(offSet, SeekOrigin.Begin)
filesStream.Write(buffer, 0, buffer.Length)
filesStream.Flush()
filesStream.Close()
filesStream.Dispose()
Else
_attachfilename = ""
End If
Catch ex As Exception
_attachfilename = ""
End Try
Return _attachfilename
End Function
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
_神__仙_
2011-12-12 · TA获得超过1256个赞
知道小有建树答主
回答量:806
采纳率:0%
帮助的人:528万
展开全部
System.IO.File.Create

SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == true)
{
Stream stream = null;
stream = sfd.OpenFile();
BinaryWriter bw = new BinaryWriter(stream);
stream.Read(Data, 0, Data.Length);
bw.Write(Data);
bw.Close();
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式