안녕하세요, ZipInputStream (예 : Unseekable 입력 스트림)을 사용하여 zip을 압축 해제하려고합니다. SharpZipLib의 도움으로 그러나 이것은 항상 나에게 오류를 제공합니다 :예외가 throw되었습니다 : 'System.IO.DirectoryNotFoundException'및 System.IO.PathTooLongException
오류 :가 슬로우
예외 : mscorlib.dll에서 오류에서 'System.IO.DirectoryNotFoundException가'경로 'C의 일부를 찾을 수 없습니다 : \ Users \ username \ Documents \ Visual Studio 2015 \ Projects \ WpfApplication1 \ WpfApplication1 \ bin \ Debug \ ASPNETWebAPISamples-master \ '에 있습니다.
나는 **ZipFile.ExtractToDirectory**
추출기 및 http://dotnetzip.codeplex.com/을 빌드했습니다. 그들도 둘 다 경로가 너무 길다 예외.
경로에 관한 몇 가지 질문을 너무 오래 동안 발견했습니다. 그러나 아무도 나를 위해 일하지 못했습니다.
이 오류를 해결하는 방법? 감사합니다. .
public static async Task HttpGetForLargeFileInRightWay()
{
using (HttpClient client = new HttpClient())
{
const string url = "https://github.com/tugberkugurlu/ASPNETWebAPISamples/archive/master.zip";
using (HttpResponseMessage response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
using (Stream streamToReadFrom = await response.Content.ReadAsStreamAsync())
{
try
{
Debug.Print("A");
UnzipFromStream(streamToReadFrom, Environment.CurrentDirectory);
Debug.Print("M");
}
catch (Exception ex)
{
Debug.Print("Error: " + ex.Message);
}
}
}
}
public static void UnzipFromStream(Stream zipStream, string outFolder)
{
ZipInputStream zipInputStream = new ZipInputStream(zipStream);
ZipEntry zipEntry = zipInputStream.GetNextEntry();
Debug.Print("B");
while (zipEntry != null)
{
String entryFileName = zipEntry.Name;
// to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName);
// Optionally match entrynames against a selection list here to skip as desired.
// The unpacked length is available in the zipEntry.Size property.
byte[] buffer = new byte[4096]; // 4K is optimum
Debug.Print("C");
// Manipulate the output filename here as desired.
String fullZipToPath = Path.Combine(outFolder, entryFileName);
Debug.Print("D");
string directoryName = Path.GetDirectoryName(fullZipToPath);
Debug.Print("E");
if (directoryName.Length > 0)
{
Debug.Print("F");
Directory.CreateDirectory(directoryName);
Debug.Print("G");
}
Debug.Print("H");
// Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
// of the file, but does not waste memory.
// The "using" will close the stream even if an exception occurs.
using (FileStream streamWriter = File.Create(fullZipToPath))
{
Debug.Print("I");
StreamUtils.Copy(zipInputStream, streamWriter, buffer);
Debug.Print("J");
}
Debug.Print("K");
zipEntry = zipInputStream.GetNextEntry();
Debug.Print("L");
}
}
디렉토리가 존재합니까? – TheLethalCoder
예'Directory.CreateDirectory (directoryName)'줄이 실제로 존재하지 않는다면 실제로 생성됩니다 – djkp
어디에서 오류가 발생합니까? 그리고 사이드 노트'fullZipToPath'는 파일 경로이고'outFolder'는 그것이 존재하는 디렉토리입니다. 왜'outFolder' 대신에'Path.GetDirectoryName (fullZipToPath)'에 디렉토리를 생성하고 있습니까? – TheLethalCoder