I am using SharpZipLib to compress with C#.
but, If any file's name is written in Korean, file name is changed.
I think I need to change encording ?
What should I do?
Please try the following:
ZipConstants.DefaultCodePage = System.Text.Encoding.Default.CodePage;
See http://community.sharpdevelop.net/forums/p/1954/36951.aspx
Related
I'm using c# fw4.5.
I have a simple code extracting a zip file.
foreach(ZipArchiveEntry entry in z.entries) //z is a zip file open in ZipArchiveMode.Read
{
entry.ExtractToFile(entry.FullName);
}
The zip file have a directory inside it and all files are inside that directory.
When I look at the z.Entries I see its an array which place [0] is only the directory and [1],[2],[3] are files.
But when its try to do:
entry.ExtractToFile(entry.FullName);
On the first entry, I get an error:
"The filename, directory name or volume label syntax is incorrect".
I can't seems to find out whats wrong. Do I need to anything also for it to open the directory? Maybe because the entry is a directory only the "ExtractToFile(entry.FullName)" can't work?
Thanks in advanced.
According to this MSDN article, the ExtractToFile method expects a path to a file (with an extension) and will throw an ArgumentException if a directory is specified.
Since the first entry in the archive is a directory and you are using its name as the argument, that is why you are having this issue.
Look into the related ExtractToDirectory method, which is used like so:
ZipFile.ExtractToDirectory(#"c:\zip\archive.zip", #"c:\extract\");
In addition to Tonkleton's answer I would suggest that you use a third-party compression library since ZipArchive is not supported for framework versions before the .Net 4.5 framework, might I suggest DotNetZip as mentioned in other questions regarding compression in earlier frameworks on StackOverflow.
Replace your paths:
void Main()
{
var zipPath = #"\\ai-vmdc1\RedirectedFolders\jlambert\Downloads\cscie33chap1and2.zip";
var extractPath = #"c:\Temp\extract";
using (ZipArchive z = ZipFile.OpenRead(zipPath))
{
foreach(ZipArchiveEntry entry in z.Entries) //z is a zip file open in ZipArchiveMode.Read
{
entry.ExtractToFile(Path.Combine(extractPath, entry.FullName), true);
}
}
}
What is the best way to get this folder path programmatically :
Windows\system32\config\systemprofile\AppData\Local ?
Sample code
HttpContext.Current.Server.MapPath();
System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
I can't write comments sorry. What are you using the path for? Where is the application stored? This will get you there??
string path = "C:\\Windows\system32\config\systemprofile\AppData\Local";
Provided C: is the name of the drive.
You really need to expand on your question a little bit.
Is this a duplicate question??
How to read existing text files without defining path
I think you can use Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData
In my project like this
string configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MyProject", "SERVICER", "config.ini");
It get Application Data Directory for all user ( contain System, Service, Guest,... ). I use it for save config of Service!!
You can get the path this way:
Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)
I'm trying to open help file (chm extension) in C#.
File.Open(#"//help.chm",FileMode.Open, FileAccess.Read, FileShare.Read);
and
FileStream fileStream = new FileStream(#"c:\help.chm", FileMode.Open);
doesn't work :(
You can use -
System.Windows.Forms.Help.ShowHelp(Control, String)
So assuming you are in a Form/Control
Help.ShowHelp(this, "file://c:\\helpfiles\\help.chm");
ShowHelp method also provides overloads to go to specific topic and help page located inside the compiled HTML help file.
Read System.Windows.Forms.Help.ShowHelp on MSDN
Decompiling a CHM file
Is as easy as executing below command in the command prompt.
hh.exe -decompile <target-folder-for-decompiled-content> <source-chm-file>
For Example:
hh.exe -decompile C:\foo\helpchmextracted help.chm
After executing the above command you should find the decompiled content in the C:\foo\helpchmextracted folder.
string helpFileName = #"c:\help.chm";
if (System.IO.File.Exists(helpFileName))
{
Help.ShowHelp(this, helpFileName );
}
if this is not work try
if (System.IO.File.Exists(helpFileName))
{
System.Diagnostics.Process.Start(helpFileName);
}
Adding my comments to an answer as per request:
It seems that the file name in the first statement is not correct however the second one
should work unless the file is locked, not exists or you don't have permissions to access the file. If you want to ShellExecute the file then you should use System.Diagnostics.Process class, but if you want to extract the contents of the CHM, since is compiled and formatted, it can't be read like plain text files.
Take a look at these links:
Decompiling CHM (help) files with C#
CHM Help File Extractor
Well the second line should be ok, if the file is not existent it should throw an exception. Need to be more specific about what you mean by " it doesn't work"
Help.ShowHelp(this, AppDomain.CurrentDomain.BaseDirectory+"\\test.chm", HelpNavigator.Topic, "Welcome.htm");
Welcome is id of the welcome age in chm file
System.Diagnostics.Process.Start(#"c:\help.chm");
Simple do this
Help.ShowHelp(ParentForm, "chmFile.chm", "link.htm");
My text file named test.txt contains
Fixing the type manager error during checkin of the elements and supporting issues during Checkin/Checkout & merge related problems.
Now i want to remove the text "supporting issues" using c#.
Please anybody let me know.
Thanks in advance,
Naveenkumar.T
if the file is fairly small you can do this:
using System.IO; // at the top of the file
string file = "path.txt"; // change to the path
// read the whole file into a string, make a replacement, then write all string to a file
File.WriteAllText(file, File.ReadAllText(file).Replace("supporting issues ",""));
Hope that helps.
I want to save one file from one path to another path.
Eg:
Original path : C:\File.txt
New path : D:\Folder\File.txt
Can i use:
File.Move("C:\File.txt", "D:\Folder\File.txt");
But i think this will remove file from original path. (C#)
Try File.Copy, i.e.
File.Copy(#"C:\File.txt", #"D:\Folder\File.txt");
You can use
File.Copy Method
Copies an existing file to a new file.
How to: Copy, Delete, and Move Files and Folders (C# Programming Guide)
Have you tried File.Copy(#"C:\File.txt", #"D:\Folder\File.txt");?
Have you tried File.Copy ?
Then you could use File.Copy.
Try File.Copy instead.
Just like this below...
System.IO.File.Copy(sourceFileName, destFileName);