silverlight如何实现下载txt文本、图片
silverlight如何实现下载txt文本、图片,而不是直接打开 请教!
[解决办法]
把文本、图片打包成rar,给个路径,点击直接下载
[解决办法]
读取文件到byte数组
byte[] data = //赋值;
string FilePath = Path.GetTempPath() + filepath;
//目录不存在则新建
if (!System.IO.Directory.Exists(FilePath))
{
System.IO.Directory.CreateDirectory(FilePath);
}
//写入文件
using (System.IO.FileStream fs = new System.IO.FileStream(FilePath + @"\" + filename, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
fs.Write(data, 0, data.Length);
}
using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
{
FilePath = FilePath + DataSelecteItem["Name"].ToString();
shell.Run(FilePath);
}
//如果读取文件不会,请参考
string filepath = AppDomain.CurrentDomain.BaseDirectory + path + filename;
byte[] data = null;
// stream 转 byte[]
Stream stream = File.OpenRead(filepath);
using (MemoryStream ms = new MemoryStream())
{
byte[] buffer = new byte[8 * 1024];
int read = 0;
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
data = ms.ToArray();
}
return data;