How to use Text file with clickonce and be able to

2019-07-02 12:46发布

问题:

I have a project and i want to use clickonce...

in the project directory, it has text files on it needed bt my applications.

  1. How can i deliver my program with the text files to my end users via clickonce?

  2. What if i change the text files, added, and removed, and modify some, how can clickonce help me to replace the old textfiles and main program in my end program.

  3. A sample pseudocode, if possible.

Tnx

Ps: the text files are used by my program but its not part of the source code.

回答1:

1) You can deliver with you programe a text file to your end user. You can embed the file in your application and deliver it with ClickOnce.

Steps (from MSDN) are :

  1. Right-click your project name, click Add, and then click Add New Item. In the New Item dialog box, select Text File from the menu, and name the file MyTextFile.txt. When the file opens in the integrated development environment (IDE), add some text, and then close the file.

  2. Right-click either the text file, and then select Properties.

    In the Properties dialog box, locate the Build Action property. By default, this property is set to Content.

  3. Click the property and change the Build Action property to Embedded Resource.

2) Everytime you will do a new version, ClickOnce will send back the new Text Resource

3)

StreamReader _textStreamReader = new StreamReader(_assembly.GetManifestResourceStream("MyNameSpace.MyTextFile.txt"));
Console.WriteLine(_textStreamReader.ReadLine());


回答2:

If you right click on your ClickOnce project and choose properties, and then click application files. If your text file and exe file is has status "include" and "required" the files will be copyed to the local client every time you release a new version of your project.

Just make sure that your clickonce project settings let clients automatically check for updates every time the application starts. (Click the "Updates" button just beneath the application files button)



回答3:

You can just add the files to your project. Set the build action to "content", and set "copy to output directory" to "copy always". Then when you publish, the files should be included with the assemblies. I assume you're letting the users access these programmatically?

When you want to change the files, just change them and publish a new version and make it a required update -- in the Updates dialog, set the minimum version to the same version you're releasing, and be sure you're checking for updates before the appliaction runs. It will create a new folder for the new version and put the text files you have in the project there, and not copy the old ones forward.