Is there a way to display the contents from memory directly in a Notepad window?
I'm assuming that I understand your question. If the file already exists on the machine you can execute the following:
System.Diagnostics.Process.Start( "notepad.exe", "[PATH]\[FILE].txt");
If not then save the file locally and then run the above code.
Double-click on the file, making sure the association is set to Notepad.
If you want Notepad to show it without saving it to disk, you can open an instance of Notepad, get the handle for the window, then write the text directly into there. You will need to use Windows User APIs to do this.
The easiest way to accomplish this is to save the file and open it in notepad, however there are at least two other ways.
Open Notepad then copy what you want to the clipboard, then using DDE force Notepad to paste. This is bad, because it potentially overwrites what the user may have been doing in the clipboard.
The second way involves getting a window handle to the notepad Edit control, then doing a WM_SETTEXT to the window. This will not, however, work across privilege boundaries (such as for apps that run as administrator, but notepad runs as a normal user). This also involves getting down to Native level and doing P/Invokes. Not exactly an easy method.
Frankly, it's just easiest to save it to a file and load it.
Why do you need notepad to show some contents (which is in memory)?
If you are using winforms, you could put it in a textbox.
Sorry, if I have not understood your question correctly.
I would like to add to MrEdmundo's answer that the Isolated Storage is the right place to store the temporary txt file for Notepad.
Related
I am trying to automate uploading a file in an Angular/Material design application. Usually, one would just SendKeys to the input box and bypass the browser 'upload file' dialog altogether. But, with Material design, the specific input element isn't available until after a file has been selected. This is the source before the file selection, and this is the source after. I need a way to manipulate the file upload box itself, or at the least enter text into the file selection input of that dialog box and hit enter. I don't know if that's possible using JavaScript Execution, or some other method, but I'm at a loss. Thanks!
I was able to find a solution. Using this documentation, I was able to add a reference to System.Windows.Forms and manually enter the file path/name and hit the enter key. I don't think this solution will work for anything that's not C#, but it worked really well for me.
I am working on a WPF 4.5 application which needs to interact with PDFs and I am stuck with an issue as described below:
I have template pdfs stored at a specific location. Based on requirement, a copy of the template pdf is created. This pdf has certain fields including text boxes, dropdowns etc. Some of these fields need to be pre-populated like the dropdown values.
Once it is ready, I need to open it, and let the user complete the form. Once completed, the user saves the file and closes it.
Now I need to read the file and send the updated data to the DB. I was able to do all this using iTextSharp by launching the PDF in a separate process and handling the Exited event. Now, the problem I face is this solution does not work if the user uses the SaveAs option to change the name or location of the opened file.
I thought if it would be possible to disable the Save options and add a button on the form clicking which would automatically save the form and close it at the expected location would be a possible solution.
My questions are:
1) Is it possible to find out using the argument of the Exited event handler to find out the saved file name and location? As soon as the user saves the file with a different name, the title of the reader gets updated with the current file name. So I am assuming that the current process is using the latest file.
2) Is it possible to disable the SaveAs and Save file options and close the file on click of a button in the form, using Adobe SDK (JavaScript or plugin or API)?
3) If I use the Adobe SDK, do all the systems on which the application would be installed need to have a licensed version of the Adobe Acrobat?
If the above options are not possible then we would have to settle with dynamic forms. We wanted to experiment with PDF since it is easy to create, and supports image annotations, for which we might need to develop a separate solution, if the above options are not feasible.
I know this is not a very specific programming question, but I need help in order to be able to figure out which path I can go on to be able to achieve the goal.
Please mark duplicate with the link to the other SO question if it a duplicate since I have not been able to figure out one.
Would appreciate answers, links to other posts on SO that are specific to the questions asked.
Please avoid opinion based answers.
Any help would be appreciated.
Any constructive criticism is also welcome.
There is a heavy-handed way to prevent an Acrobat user from Saving a file. In Acrobat, create a Javascript that executes when "Document Will Save." A script like this causes the application to hang rather than Save the file:
var key = "" + this.getField("Password").value;
if (key != "QWERTY") {
app.alert ("No changes to this PDF are allowed,
so you may not Save it.
You will now have to Force Quit or End Task.");
while (true) {};
}
I am not proud of this, but it does the job. You might want to erase the password field before saving.
Im working on automating the behavious of a scientific measurement program in C#.
The program does have a .net API, but the developers of the program havent included all necessary commands eg. they havent included a simple "save as" command that i need for saving the measureing data.
Is there a way to operate the menu strip of the application and e.g. press the save as button.
I start the program from my own application by means of Process.Start();
One simple solution - copy destination path to the clipboard, then use e.g. SendKeys.SendWait() to send the following keys to your target application (with sufficient pauses between them) Ctrl+S "^s", Ctrl+V "^v", Enter "{ENTER}".
It's also a good idea to verify the folder exists, and the file does not, otherwise the saving will obviously fail, or overwrite confirmation will popup.
P.S. But before doing that, use e.g. .NET Reflector to ensure their .NET API doesn't have the save functionality: there're many cases where the SendKeys approach will fail.
I am writing a utility copying files to/from remote drives (eg SkyDrive). When I'm about to overwrite a file, I pop up a regular "file exists, do you want to overwrite Y/N" message box; is it possible to use the standard Windows file overwrite dialog instead? With the three options (copy and replace, don't copy, copy but keep both) and the more detailed size / date information? Or should I just write my own form to duplicate that? (To be honest, I've been searching for this for two days, it would probably have been much faster to just write my own.)
To clarify: I need to show up that dialog when I choose to - sometimes I don't want to show it and just want to overwrite the file.
If at all possible, I would prefer for this to work in C# / .NET; however, if only an unmanaged solution exists I'll take that too.
Yes, it is possible! I did this for Send to Dropbox a little add-on utility I wrote for Explorer to right click and send files to a dropbox folder.
Copy SHFileOperation.cs into your project, and you can invoke it like so:
ShellFileOperation.CopyItems(source, target);
source can have multiple files/directories. Each item must be enclosed in quotes (").
target is the destination directory.
Example:
ShellFileOperation.CopyItems("\"c:\\foo.txt\" \"c:\\bar.txt\"", "d:\\xyz");
I have written a winform application in visual studio 2010.In one of the forms the user can browse the local system and select an image, so the application will copy that image(with File.Copy() method) to its folder.
the problem is when the user wants to delete that image(File.Delete() method),I receive an error like this :
cannot delete this file because it is used by another process.
I do not know what this error says because i do not use the image files in other processes.
cannot delete this file because it is used by another process.
The message isn't terribly helpful to programmers because when it happens when you develop code, that other process is almost always your process.
This is very likely to occur with image files, creating a Image or Bitmap object from an image file puts a lock on the file. The lock is created because GDI+ creates a memory-mapped view on the file content, a strong optimization that keeps the bitmap data out of the paging file. Matters a great deal on large images, they can contain many megabytes worth of pixel data.
That lock is kept until you explicitly call its Dispose() method in your code. So be sure that was done before you try to save the image back. In rare cases you may need to create a copy of the image to allow you to dispose the original, use the Bitmap() constructor overload that takes an Image argument.
What is happening is that when we copy a file from C# code and paste it, even after that program maintains a link/information to original/copied file. This will not happen to files not copied by program or files already present in your folder.
An alternative of this is to fire copy shell/dos command. A way to do that is present in this article
normal copy command in dos is like
copy originalfilenamewithpath destinationfilenamewithpath.
To know more about copy command go to dos and write copy /? and press enter.
Agree with what Conrad suggested, though there are edge cases where Process Explorer may not be reliable, alternatively you can try Unlocker