Update application through ftp - c#

I am having strange problem while updating my application through ftp. I am uploading files to a folder in ftp by Ipswitch WS_FTP.
I am updating files in remote folder to check my code. But it is downloading old files which were rewritten in remote folder.
Here is details. I have a folder update. Inside of this folder 2 files. version.txt and app.zip
In old files I used capital letters such as VERSION.txt, In new file small capitals.
But I can not reach new files. Why? I can reach only old files which is VERSION.txt
With app.zip the same problem, I am updating its files inside zip file. But getting old files from zip file.
PS. I am changing files inside app.zip and uploading it to remote folder but I can not reach new files inside app.zip. I can reach only old files. The problem is refreshing of files inside app.zip. Or I have problem with cache or something else?

If the server is on linux, you should note linux is file system is camel case (window is not), so in linux file.txt != FILE.txt and in windows are the same file. Hope this tips, helps.

Related

How to create text file in .NET project folder, not in bin/Debug folder where is by default

I have a very simple .NET console application in Visual Studio. I am trying to write some words into a text file.
using (StreamWriter file = File.AppendText("log1.txt"))
{
file.WriteLine("Hello from the text file");
}
If the file does not exist, the application creates it in the autogenerated folder bin/Debug.
Is there a way to create this file in the project's directory, where I have .csproj file?
And more important, in real-world applications, when you work with files, you keep them in bin/Debug? That's why .NET creates them there firstly?
Is there a way to create this file in the project's directory, where I have .csproj file?
Yes, but this can only be done while you are working on your project. Once you are done developing it and try to publish it you won't have access to the location where you have .csproj file, because after publishing you can install it on any PC and it wont have the project you are working on.
And more important, in real-world applications, when you work with files, you keep them in bin/Debug?
No, I assume by real-world applications in your context you mean a published project '.exe' that you can run on any PC. Windows provides you three Data folders that you should use when writing your program so that it works smoothly after publishing:
User Data
Roaming User Data
All User Data
You can acess the above folders in .NET application using the Environment.SpecialFolder:
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
As per your given code, try this :
var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"log1.txt");
using (StreamWriter file = File.AppendText(fileName))
{
file.WriteLine("Hello from the text file");
}
This way you will be able to publish your program and it will still work smoothly without hard-coding the path as you were doing previously.
That's why .NET creates them there firstly?
If you don't specify a complete path, and just the file name .NET looks into the working directory of the executable, which in this case is bin/Debug
Is there a way to create this file in the project's directory, where I have .csproj file?
Yes. As explained here (second answer) you can use the post-build event to write down the value of $(ProjectDir) in a text file (using command echo $(ProjectDir) > ..\..\projectdir.txt). This macro contains the directory of your .csproj. This command will create the file projectdir.txt with your project directory after a build process so you read this file contents in your code and use what is inside it to pass to File.AppendText as the base directory to create your file log1.txt.
And more important, in real-world applications, when you work with files, you keep them in bin/Debug? That's why .NET creates them there firstly?
That depends on what you want to do. In your case the code creates the file at bin/Debug because that is where your executable are being executed. When you omit the full path to File.AppendText and just pass "log1.txt" as argument, it will create the file in the same folder as the executable are at. If you want a different folder you should specify the folder here (e.g. File.AppendText("C:/log1.txt") will create the file at C:/.
You can create the text file in the root of your project and use copy always to have them in the same place as your executable. If this is just a readonly text file then it's OK because windows doesn't allow you to modify the files reside in Programs folder in OS drive.
If you want your code to modify these text file then you need to put them in appdata folder. In real world example I did this on many project. All the database work my winforms, WPF application need goes in AppData folder.

Reading zipped folder with empty subdirectories causes problems

I'm running into a strange problem using ZipFile and ZipArchive with .Net 4.5.
ZipFile.CreateFromDirectory takes all content of a directory, including folders that are empty.
If I try to create the same zip file using Windows explorer by right clicking > Send to > Compressed folder, I get a warning message saying the empty folder was omitted.
I'm loading the resulting zip file into an application that runs on Apache Tomcat. This application throws errors for every single file contained in the zip that I produced with ZipFile.CreateFromDirectory. The zip that I created manually through Windows explorer is read just fine.
I suspect the problem lies in the empty zipped folders, but haven't yet been able to definitively conclude this. If the empty folders are the cause, I'd need a way to use ZipFile.CreateFromDirectory excluding empty folders.
Taken from my comment above:
I have no .NET 4.5, but from the remarks section: "The directory structure from the file system is preserved in the archive. If the directory is empty, an empty archive is created." So this is by design.
So you either have to
fix it in the comsuming app on tomcat or you have to
create a temporary folder which just contains the non-empty folders, if possible
I haven't found a way to exclude empty folders in CreateFromDirectory in the first place.
Alternatively, I can remove empty directories from the created zip file. Though this still causes errors in the Tomcat application.
// compress and copy new zip
ZipFile.CreateFromDirectory(dirtocopy.FullName, NewZipFilePath);
using (ZipArchive za = ZipFile.Open(NewZipFilePath, ZipArchiveMode.Update))
{
// only empty folders end with \
List<ZipArchiveEntry> emptyFolders = (from ZipArchiveEntry zae in za.Entries
where zae.FullName.EndsWith("\\")
select zae).ToList<ZipArchiveEntry>();
emptyFolders.ForEach((ZipArchiveEntry folder) => folder.Delete());
}

Adding a whole folder (with subfolders) as embedded resource?

I have an application that upon execution It copies two folders with subfolders that are in the same location to another windows location %AppData%
Now I have the following files :
MyApp.exe , Folder1, Folder2
In each folder there are subfolders. How to embed these two folders as resources inside the application so after compiling the program, I get only one executable file. And when I click on it, it extract the two folders to the same location then do the rest of job.
I know how to add a file as embedded resource then retrieve it using reflection,
but how about a folder Is that even possible??
I had to solve this problem recently. I embedded a ZIP file, and then decompressed it at runtime.
.NET 4.5 includes ZIP functionality. If not, use SharpZipLib or DotNetZip.

Copying the most recent file on a server to a local directory

I am trying to figure out how to copy the most recent file in a server directory to a local directory in c#.
I am needing to do this to over 100 directories. They will all copy and rename to the same local directory.
The directories all named: e.g. \ServerPath\01, \ServerPath\02, \ServerPath\03, etc.
Right now I have a batch script that will do it but it takes forever since it goes through each and every file in each directory.
My immediate thought was "Is this possible with Robocopy??" I did a quick search on Google for "Robocopy most recent file" and came up with a blog post about handling this with a powershell script.
This should at least provide you the latest files without you having to go through "...each and every file in each directory".

database connectivity in c#

I am working on c# windows project.I am using Microsoft Access database with OleDbConnection connection.My database "email.mdb" is in My document directory and my "email_db.udl" is in "D: drive".This is running well on my computer.But whenever i am making an exe installer file for installment on other Pc this is not working.I am placing "mdb" and "udl" file is in same directory as they are on my PC.I am supposing this ('udl' file) is not connected with my database.
How will i resolve this problem for installation on any windows pc.
Thanks
You can put the database files in your project's directory (where sln file is) and access them through their bare filenames (without D:...., only filename).
In case of the installation you have to set the installer to put it in the installation folder (where the exe file is)
This is a good way to carry everything in one folder and be organized.
Probably here you have a problem because the "My Document" directory has a different path in every PC.

Categories

Resources