SharpZipLib - IO Exception while unzipping file - c#

I am using SharpZipLib in my application to Unzip files. I have a folder in which the zip is copied and is extracted there itself. ZIP and Folder name is a guid.
Folder mostly contains 1 or 2 XML files of size 45kb on an average.
Following is the SAN storage where we store all the files (its not exact):
\\sharableFolder\Folder1\Folder2\Folder3
Few days ago errors were logged.
The following error was logged continuously whenever unzip operation was performed:
An attempt was made to create more links on a file than the file system supports
We googled about this issue and we found following links:
https://msdn.microsoft.com/en-us/library/cc231199.aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ms681383
But we did not find help to resolve it.
We checked:
Limit of files and folders a Folder can contain
For FAT : Maximum number of files in a single folder: 65,534
For NTFS : Maximum number of files in a single folder: 4,294,967,295
We assumed that there is an issue with the no of ZIP files. Currently there are total 1,31,760 files (Zip and Folders) present. We created 1,00,000 ZIP files and also extracted same no of files using ICSharpZipLib. So in total there were 2,00,000 files in a folder. Our assumption that a folder can not contains 1,31,760 files was failed.
We tried alternate code to unzip file. That also didn't work.
We checked for path whether its too long. But that is also not the case.Path was in limit.
We tried moving out few thousand files. But this solution even didn't work.
Lastly we created a new folder and updated the path with the new folder. It worked properly.
But I want to know what could be the cause of this issue. This may happen with other folder on Production.
Any help is appreciated. Thanks in advance
Following is stack trace:
type="System.IO.IOException"
message="An attempt was made to create more links on a file than the file system supports."
source="mscorlib"
detail="System.Exception
System.IO.IOException: An attempt was made to create more links on a file than the file system supports.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
at ICSharpCode.SharpZipLib.Zip.FastZip.ExtractEntry(ZipEntry entry)
at ICSharpCode.SharpZipLib.Zip.FastZip.ExtractZip(Stream inputStream, String targetDirectory, Overwrite overwrite, ConfirmOverwriteDelegate confirmDelegate, String fileFilter, String directoryFilter, Boolean restoreDateTime, Boolean isStreamOwner)
at ICSharpCode.SharpZipLib.Zip.FastZip.ExtractZip(String zipFileName, String targetDirectory, Overwrite overwrite, ConfirmOverwriteDelegate confirmDelegate, String fileFilter, String directoryFilter, Boolean restoreDateTime)
at MyProject.ProjectFile.File.UnzipFile(String ErrorFile, String& ErrorXMLPath, String& FEXMLPath, String mXMLPath)
at MyProject.ProjectFile.File.ValidateUnzippedFile(Object items)
--- End of inner exception stack trace ---

Related

NAS: System.IO.IOException: Insufficient system resources exists to complete the requested service

I have a console app. (C# written in VSCode) which is looking through files (>200000 at a time) and gather data out of them.
It is working without any problem if the source and destination folders are on the local computer. Also good if the source&destination are shared folders on another PC.
Problem occurs when I set the source&destination to point to a NAS (shared folder).
I am thinking it is a memory issue, but how could I be sure out of this error message:
Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft
Corporation. All rights reserved. Unhandled exception.
System.IO.IOException: Insufficient system resources exist to complete
the requested service. :
'W:\2020-08\2020-08-18\ID_GEBER_NG21_BOT\VC52034208097F01BCS' at
System.IO.Enumeration.FileSystemEnumerator1.CreateRelativeDirectoryHandle(ReadOnlySpan1
relativePath, String fullPath) at
System.IO.Enumeration.FileSystemEnumerator1.MoveNext() at System.Collections.Generic.LargeArrayBuilder1.AddRange(IEnumerable1 items) at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable1
source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1
source) at System.IO.Directory.GetFiles(String path, String
searchPattern, SearchOption searchOption) at
ExtractMtagtoCSV.Program.Main() in C:\temp\ExtractMtagtoCSV - v2 -
testovernetework\Program.cs:line 80
Content of "line 80":
string[] filePaths = Directory.GetFiles(#"W:\\2020-08","*.mtag", SearchOption.AllDirectories);
The application using far less then 1GB according to the VScode's Process explorer, the NAS has 4GBs.
Anybody could help?
I would suspect that there are simply too many files in that shared folder. The assignment
string[] filePaths = Directory.GetFiles(#"W:\2020-08","*.mtag", SearchOption.AllDirectories);
is finding all the files in all the subdirectories and saving their names into the array as explained in the documentation of GetFiles. That page suggests that you should instead use the EnumerateFiles method and not assign the results to an array, but process them via an iterator.

Unable to delete a desktop folder

Problem: I am unable to delete a folder (including contents) within a
desktop folder programatically with C#. If I copy the value of
desktopDestinationPath and paste it into Windows Explorer, I can open
this folder (conclusion, the path is valid) The test -
Directory.Exists(desktopDestinationPath) - returns as true and I drop
into the code block (conclusion, the path is valid)
Directory.Delete(desktopDestinationPath, true) - throws exception
(conclusion, path no longer valid) If I copy the path value from the
exception and paste it into Windows Explorer, I can open this folder
(conclusion, the path is valid)
What I have tried: Build, Rebuild, Clean Solution, restart visual
studio. Also, If I delete the folder manually and run the code, the
folder is successfully built. However, when I run a second time, I get
the exception. Result: Puzzled look and this post. Sorry if I put
too much detail. I am open to help with a solution and criticism on
how I posted (both will help me learn) Thanks in advance! Visual
Studio Info is toward the bottom of this entry. I am using: Microsoft
Visual Studio Premium 2013 (C#).
My code:
// preceded by other code in the method
if (Directory.Exists(desktopDestinationPath)) // desktopDestinationPath is "C:\\Users\<me>\\Desktop\\<folder 1>\\<folder 2>"
{
Directory.Delete(desktopDestinationPath, true); // exception is thrown here <***> "C:\\Users\\<me>\\Desktop\\<folder 1>\\<folder 2>"
// create folder
Directory.CreateDirectory(desktopDestinationPath);
// Call a method to perform Xcopy
ProcessXcopy(SourceLoc, desktopDestinationPath);
}
// followed by an else which creates folder if it does not exist
My code is throwing the following exception: // NOTE I am using Pri.Longpath
System.IO.DirectoryNotFoundException was unhandled by user code HResult=-2147024893 Message=Could not find a part of the path 'C:\Users\ljones\Desktop\folder 1\folder2\fldr3\fldr4\fldr5\fldr6\fldr7\fldr8\fldr9'. Source=mscorlib StackTrace: at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound) at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost) at System.IO.Directory.Delete(String path, Boolean recursive) at UnitTests.GatMinerTest.CreateDesktopDestinationFolder(String desktopPath) in c:\Users\some folder\Source\Workspaces\some folder\some folder\some folder\some file:line 93 at UnitTests.GatMinerTest.IcwIntegrationMethod() in c:\Users\some folder\Source\Workspaces\some folder\some folder\some folder\some file:line 65 InnerException:
From the web I have learned: A DirectoryNotFoundException exception
is thrown when part of a file path or a directory is not found. Verify
that the directory appears in the specified location. Check that the
directory exists in the specified location. // I am fairly (99.9%)
certain the directory exists When using relative paths, make sure the
current directory is correct. The path may be incorrect if you are
assuming an incorrect current directory. // I am fairly (99.9%)
certain the directory exists
Thank you all for your help in finding an answer. Specifically, thanks for the tips on posting a question in a more appropriate manner.
The solution was an error on my part (go figure).
In code that I did not disclose, there is a call to xcopy. I believe during testing, I had ran past that point and xcopy was working in the background (still had its hooks into my folder structure). Therefore, I couldn't delete it.
My apologies if I wasted your time. Your nudges helped push me toward finding the error in my ways.
Thanks again!

crystal reports Issue in path file

After making a published version of asp.net webform application and uploading it to my clients server the application worked correctly.
But after time it showed this error:
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename)
at LogisticSystem.eokReports.ExportReportPage.GetReport()
in D:\Mostafa\LogisticSystem\LogisticSystem\eokReports\ExportReportPage.aspx.cs:line 390
this path is my local pc path
"D:\Mostafa\LogisticSystem\LogisticSystem\eokReports\ExportReportPage.aspx.cs" not a path at the clients server
It looks like you are trying to load a file that is not present at the clients server. Make sure that your report path is correct and the file exists. If "D:\Mostafa\LogisticSystem\LogisticSystem\eokReports\ExportReportPage.aspx.cs" not a path at the clients server is your error, then it's pretty clear that the file path you specify in your code does not exist on the server. Put the report file on the client's server and change your code to point to that file location instead of the location on YOUR machine.
Hope that helps,
Chris

WmAutoUpdate - anyone used it? Won't roll back

I've built a Compact Framework application and I'm using WmAutoUpdate to deploy new versions to the mobile devices (http://www.sebastianvogelsang.com/2009/09/23/wmautoupdate-a-net-compact-framework-auto-update-library/). Has anyone used this? It's cool but I've got a problem.
If I cause the application to crash half-way through updating it is supposed to recover by copying the backup version back into the main directory. This doesn't work because the exe file is "locked" by the operating system because it is currently in use. I can verify this is the case because I can't delete it using Windows Explorer either. The error details are:
System.IO.IOException was unhandled
Message="IOException"
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.File.Move(String sourceFileName, String destFileName)
at WmAutoUpdate.Updater.assertPreviousUpdate()
at WmAutoUpdate.Updater..ctor(String url)
The error occurs on this line in Updater.assertPreviousUpdate():
File.Move(f, appPath + "\\" + getFilenameFromPath(f));
The code manages to update the application exe file when it's allowed to run normally (I'm not sure how). The problem is that it doesn't work when rolling back.
Cheer
Mark
I've used WmAutoUpdate and I've found the same problem. The issue is that you can move the files of the actual running process, but you cannot overwrite them. If you check the update part, WmAutoUpdate moves the running application to a backup directory and then it writes the update version to the original directory. I have fixed the rollback part this way:
if (Directory.Exists(backupDir))
{
string tmpDir = Path.Combine(Path.GetTempPath(),Path.GetFileNameWithoutExtension(Path.GetTempFileName()));
Directory.Move(appPath, tmpDir);
Directory.Move(backupDir, appPath);
}
First we move the running application files to a random directory in Temp. Then we copy the backup folder to the application original directory. Of course, this will generate a .TMP file in the Temp directory of your device, and a folder with the actual running process. You will have to delete this temporary folder once in a while in production code.

Transferring files from one PC to another using C#?

I'm using C#. I want to get the files that are on the server PC to my PC. Both PCs are connected through network.
I have given IP address of that PC in the path, but it's not copying the files to my folder. I'm using the following code, but it's not working:
File.Copy(Path.GetFileName(sourceFile), Path.GetDirectoryName(targetpath));
In sourceFile I have given IP address + folder path of the server PC and in the targetpath i have given the path of the folder of my PC to which I want to copy the files.
Wy do you use Path.GetFileName?
This function get only file name, not full path.
The signature of File.Copy(string sourceFileName, string destFileName) means, that you must use full path to both files.
This code works good:
File.Copy(#"\\server\folder$\test.txt", "test.txt");

Categories

Resources