雅蠛蝶,救命啊。。。ICSharpCode问题,路径访问被拒绝啊
private string CreateZIPFile(string path, int M)
{
try
{
Crc32 crc = new Crc32();
ICSharpCode.SharpZipLib.Zip.ZipOutputStream zipout = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(System.IO.File.Create(path + "\\" + DateTime.Now.ToString("yyyyMMddHH") + ".zip"));
System.IO.FileStream fs = System.IO.File.OpenRead(path + "\\" + DateTime.Now.ToString("yyyyMMddHH"));
long pai = 1024 * 1024 * M;//每M兆写一次
long forint = fs.Length / pai + 1;
byte[] buffer = null;
ZipEntry entry = new ZipEntry(System.IO.Path.GetFileName(path + "\\" + DateTime.Now.ToString("yyyyMMddHH")));
entry.Size = fs.Length;
entry.DateTime = DateTime.Now;
zipout.PutNextEntry(entry);
for (long i = 1; i <= forint; i++)
{
if (pai * i < fs.Length)
{
buffer = new byte[pai];
fs.Seek(pai * (i - 1), System.IO.SeekOrigin.Begin);
}
else
{
if (fs.Length < pai)
{
buffer = new byte[fs.Length];
}
else
{
buffer = new byte[fs.Length - pai * (i - 1)];
fs.Seek(pai * (i - 1), System.IO.SeekOrigin.Begin);
}
}
fs.Read(buffer, 0, buffer.Length);
crc.Reset();
crc.Update(buffer);
zipout.Write(buffer, 0, buffer.Length);
zipout.Flush();
}
fs.Close();
zipout.Finish();
zipout.Close();
System.IO.File.Delete(path);
return path + ".zip";
}
catch (Exception ex)
{
string str = ex.Message;
return null;
}
}
path到底是写文件路径,还是目录啊?目录跟我说访问拒绝,文件路径跟我说文件被另一个进程用着。
压缩
ICSharpCode
--------------------编程问答--------------------
打开文件目录啊
--------------------编程问答--------------------
path 写文件路劲
--------------------编程问答--------------------
怎么打开- -
--------------------编程问答--------------------
我写C:\Test这么个路径- -跟我说拒绝访问啊
--------------------编程问答--------------------
在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
在 System.IO.File.OpenRead(String path)
在 Service.CreateZIPFile(String path, Int32 M) 位置 c:\workspace\VSTS\ProductMaintenace\Codes\医卡通实时结算\文件获取\FileService\App_Code\Service.cs:行号 216
报错是这样的- -救命啊
--------------------编程问答--------------------
加断点看那句抛出的异常啊~~
--------------------编程问答--------------------
System.IO.FileStream fs = System.IO.File.OpenRead(path + "\\" + DateTime.Now.ToString("yyyyMMddHH"));
注释这句,try。。。。
--------------------编程问答--------------------
System.IO.FileStream fs = System.IO.File.OpenRead(path + "\\" + DateTime.Now.ToString("yyyyMMddHH"));
注释这句,try。。。。
就是这句异常拉,说拒绝访问该路径啊,path为C:\目录地址的话,而如果是定位到文件的路径C:\2013XXXX.zip的话就是说呗另一个进程调用,就是这样
--------------------编程问答--------------------
呀咩跌都出来救人了么
--------------------编程问答--------------------
设置文件共享方式为读写,FileShare.ReadWrite
--------------------编程问答--------------------
呀咩跌都出来救人了么
雅蠛蝶,吖见死不救啊- -
--------------------编程问答--------------------
设置文件共享方式为读写,FileShare.ReadWrite
因为不是用的fileStream- -不知道怎么设置fileShare啊- -写了都不对的说
--------------------编程问答--------------------
System.IO.FileStream fs = new System.IO.FileStream(path + "\\" + DateTime.Now.ToString("yyyyMMddHH"), System.IO.FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite);
--------------------编程问答--------------------
System.IO.FileStream fs = new System.IO.FileStream(path + "\\" + DateTime.Now.ToString("yyyyMMddHH"), System.IO.FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite);
= =我也是这样想的- -但是试了试不行啊蛋疼。。。
--------------------编程问答--------------------
不懂了。。。求懂
--------------------编程问答--------------------
不懂了。。。求懂
哭啊- -同求
--------------------编程问答--------------------
== 放弃这种写法了,改为将文件夹的所有目录列表取得,然后在根据地址一个个文件获取- -
补充:.NET技术 , C#