I am developing a Windows Forms app in c# that will make changes to a document and I want to include a button that will open the before and after in winmerge.
If it is possible, how do I do it?
More Detail:
I want to click a button Show Result with the starting file in the textbox.
It should open winmerge and open this dialog with the original file on the left and updated file on the right.
So far I have:
Process notePad = new Process();
notePad.StartInfo.FileName = "WinMerge.exe";
notePad.StartInfo.Arguments = txtIn.Text;
notePad.Start();
The updated file is in the same directory as the input file one level down in a folder called "UPDATED"
String leftFilePath = "...";
String rightFilePath = "...";
string exe = "winmergeu.exe";
String args = $#"""{leftFilePath}"" ""{rightFilePath}""";
Process.Start(exe, args);
Related
I have a problem Where I cant make my program automatically read the given file path inside the .dat and be ready to launch the program when pressing launch file without opening openFileDialog and choosing the program every time.
the code im using here is for the user to enter the file path for the first time then create a file path .dat file and it works with now issues.
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string path = Path.Combine(desktop, "LS\\Fail-SafePath.dat");
openFileDialog.InitialDirectory = filePath;
openFileDialog.Filter = " PlayGTAV (*.exe)|PlayGTAV.exe";
openFileDialog.FilterIndex = 1;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
filePath = openFileDialog.FileName;
var fileStream = openFileDialog.OpenFile();
using (StreamReader reader = new StreamReader(fileStream))
{
fileContent = reader.ReadToEnd();
}
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine(filePath);
}
After that that i have a start button for it
private void panel21_MouseClick(object sender, MouseEventArgs e)
{
Process.Start(filePath);
}
This works well when the user does it for the first time but now I want it to read that .dat file path automatically without having to ask the user for the file path every single time which I don't know how to do and need help with please.
I was thinking to do it like that: When Pressing the Launch button (After the first time) The Program Checks if the Fail-SafePath.dat Exists if Yes it reads the lines from it and starts the program from the given path without opening OpenFileDialog.
I'm Using Visual Studio, Windows Form.
If it's a file that the application will always need, then something like you mentioned:
I was thinking to do it like that: When Pressing the Launch button (After the first time) The Program Checks if the Fail-SafePath.dat Exists if Yes it reads the lines from it and starts the program from the given path without opening OpenFileDialog.
Could work easily enough. You could have your application look for it in the default location, and if not there, have your user select it.
Another solution could be using something like Application Settings or User Settings, which are values persisted between executions of .NET projects.
Depending on your full application design, you could also have the file path and other settings stored in some database or other data storage. There are a lot of ways to accomplish this.
EDIT: To elaborate further on the Application Settings
The application settings are very easy to read and write to.
You just need to create the ones you want, before trying to use them.
They can be created by:
Open Visual Studio.
In Solution Explorer, expand the Properties node of your project.
Double-click the .settings file in which you want to add a new setting. The default name for this file is Settings.settings.
In the Settings designer, set the Name, Value, Type, and Scope for your setting. Each row represents a single setting.
To read from your settings:
this.FilePath= Properties.Settings.Default.FilePath;
To write to and save the setting:
Properties.Settings.Default.FilePath= Path.GetFullPath("importantFilePath");
Properties.Settings.Default.Save();
I'm beginner developer. I'm building a windows desktop form application like a notepad. The user will fill contact info and add text when the information is loaded, the user should be able to save the form as .pdf file and the possibility to print out the entire form directly, same as it was loaded. Which the best and quick alternative to accomplish this on c#?
Save a .pdf file at least on C#
You can use an installed PDF Reader by this:
Process prcs = new Process();
prcs.StartInfo = new ProcessStartInfo()
{
CreateNoWindow = true,
Verb = "print",
FileName = #"your file path"
};
prcs.Start();
I'm attempting to do two things. I want to embed a text file into my project so that I can utilise it and modify it, but at the same time I don't want to have to package it when I send the project out to users (I.E included in the exe file).
I've had a look around and there's been multiple questions already but I just cant seem to get any to work. Here's the steps I've taken so far;
Added the text file to my "Resources Folder"
Build action to "Content" and output directory to "Do not copy"
I then try to access the file in my code;
if (File.Exists(Properties.Resources.company_map_template))
{
MessageBox.Show("Test");
var objReader = new StreamReader(Properties.Resources.company_map_template);
string line = "";
line = objReader.ReadToEnd();
objReader.Close();
line = line.Replace("[latlong]", latitude + ", " + longitude);
mapWebBrowser.NavigateToString(line);
}
The MessageBox never appears which to me means that it cannot find the file and somewhere somehow I've done something wrong. How can I add the file into my project so I don't need to distribute with an exe whilst being able to access it in code?
I would use the following:
BuildAction to None (not needed)
and add your file to Resources.resx under files (using DragAndDrop from SolutionExplorer to opened Resources.resx)
Access to your Text:
using YOURNAMESPACE.Configuration.Properties;
string fileContent = Resources.company_map_template;
Then you're done. You don't need to access through StreamReader
When i publish my windows application for a cd/usb , i want that pdf iclueded with application. And when install the program, pdf must copied to user's computer. Then i must know the pdf file's directory for click event. What should i do?
Note: I'm sorry for my bad english. I hope that explain my problem.
Here's picture from my app;
After edited;
pdfFullPath = Path.GetFullPath("Kullanım Kılavuzu.pdf");
and my buttons like;
private void btnFirma_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(pdfFullPath);
}
As Oguz said, ensure that the PDF is included in the build path first.
If your executable is always going to be in a fixed directory structure. So you will know where the pdf is in relation to the application. You can try:
string pdfFullPath = Directory.GetCurrentDirectory() + "\\document\\Kullanım Kılavuzu.pdf";
Almost forgot your working directory might be off.
In your button click try:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = pdfFullPath;
startInfo.WorkingDirectory = Directory.GetCurrentDirectory() + "\\document";
Process.Start(startInfo);
Right click the pdf file and click properties, then in the properties window set the following properties:
Build Action: Content
Copy to Output Directory: Copy always
After publishing your app, the file will be at this path:
string pdfFullPath = Path.GetFullPath("Kullanım Klavuzu.pdf");
I would like to programmatically open a document from a SharePoint URL.
I have the following code:
Process wordProcess = new Process();
wordProcess.StartInfo.FileName
= "http://sharepoint/blank_site_1/document library 1/word document.docx";
wordProcess.StartInfo.UseShellExecute = true;
wordProcess.Start();
This opens a webbrowser window and downloads the file, which is not what I want. If I append
wordProcess.StartInfo.Verb = "OpenAsReadOnly"
as per (the documentation) I get a Win32 Exception "The parameter is incorrect" at wordProcess.Start(), despite the verb being present in wordProcess.StartInfo.Verbs when examining in the debugger.
I have a POC which does this by extracting the default program from the registry, building a command and starting the program with the filename, but I'd rather not go down that route if this can be easily solved, as all I want to do is open a file (the path of which just happens to look like a URL) with the default program.
Just a guess, try this:
wordProcess.StartInfo.FileName = "winword.exe";
wordProcess.StartInfo.Arguments = "\"http://sharepoint/blank_site_1/document_library_1/word document file.docx\"";