我找到了上传代码,这段代码包含了该Stream.CopyTo方法.
例:
file.Stream.CopyTo(requestStream); // .NET Framework 4.0
Run Code Online (Sandbox Code Playgroud)
如何将"file.Stream"复制到"requestStream"?
所以我已经实现了压缩文件,但现在我有另一个问题,zip文件夹包含空文件.压缩文件的大小为0字节.
这就是我压缩文件的方式
try
{
var outPutDirectory = AppDomain.CurrentDomain.BaseDirectory;
string logoimage = Path.Combine(outPutDirectory, "images\\error.png");
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.BufferOutput = false;
HttpContext.Current.Response.ContentType = "application/zip";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=pauls_chapel_audio.zip");
using (MemoryStream ms = new MemoryStream())
{
// create new ZIP archive within prepared MemoryStream
using (ZipArchive zip = new ZipArchive(ms, ZipArchiveMode.Create, true))
{
var demoFile = zip.CreateEntry(logoimage);
// add some files to ZIP archive
}
ms.WriteTo(HttpContext.Current.Response.OutputStream);
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
另一个问题是压缩文件夹的路径与图像的路径相同.所以它就像
ZippFolder/A/B/C/image...
Run Code Online (Sandbox Code Playgroud)
我只需要
ZipFolder/content
Run Code Online (Sandbox Code Playgroud) 我正在使用vb.net win form.我的任务是将文件夹中的文件名显示在gridview控件上.当用户点击我的UI中的进程按钮,gridview中存在的所有文件名时,相应的文件必须一个接一个地加载到内存流缓冲区,并将标题附加到文件的内容并将其保存在硬盘驱动器中,并带有_ed as文件名的后缀.
我是非常基本的程序员.我已完成以下尝试并成功将文件名显示在gridview上.但不知道以后的部分.有什么建议吗?
'将文件夹中的文件显示在gridview上
Dim inqueuePath As String = "C:\Users\Desktop\INQUEUE"
Dim fileInfo() As String
Dim rowint As Integer = 0
Dim name As String
Dim directoryInfo As New System.IO.DirectoryInfo(inqueuePath)
fileInfo = System.IO.Directory.GetFiles(inqueuePath)
With Gridview1
.Columns.Add("Column 0", "FileName")
.AutoResizeColumns()
End With
For Each name In fileInfo
Gridview1.Rows.Add()
Dim filename As String = System.IO.Path.GetFileName(name)
Gridview1.Item(0, rowint).Value = filename
rowint = rowint + 1
Next
Run Code Online (Sandbox Code Playgroud)
非常感谢您花费宝贵的时间阅读这篇文章.