Ive been trying for a while now to get a rich textbox to populate from a text file. Normally I would say this is easy and there are tons of solutions on here for it. My only issue is I don't want the open file dialog to populate it I want it to be populated on the onload event of the form, and populate from a known text file on the network drive here. Every solution I find seems to be asking for the users input to open the file I don't want this. This is due to the fact that when the text file is edited( which it will often be) I want the textbox to mimic this rather then have an outdated version hard coded in. Please help
If you know the location then
const string Myfile = #"c:\test\myfile.rtf";
richTextBox1.Loadfile(Myfile);
you can use UNC etc, but it may error if it cant find the file - so I would suggest file checks etc.
Use System.IO.FileSystemWatcher to watch for changes to the file, and then System.IO.File.ReadAllText to read the contents of the file into your textbox.
Related
I want to achieve the following:
I copy some text in a Word application (or another application where the clipboard is updated with text). I now want to know the location path of the Word document, so I can store the path and open the document for a reference later on.
I would like to do it for websites as well, so I can get the website where the text was copied from.
I want do this in C# and Windows 10. My initial thought was to create a CTRL + C event listener, and find the active application and get the location like that. But I cant link the copied text, and the text path together.
Any ideas out there?
You can retrieve such information, but with limitaions. When there is no such information stored in clipboard you're out of luck, but, hopefully for you, many applications store way more data in clipboard along with text, including path or url to the document.
Different applications using different different formats to track document location, so main idea is to try read from clipboard all relevant clipboard formats that include document location one by one and try to extract location.
Here several clipboard formats that contains or can contain information needed to you:
HTML Format
msSourceUrl
FileName and FileNameW
UniformResourceLocator and UniformResourceLocatorW
ObjectLink
Hyperlink
etc.
You can find more about different clipboard formats here. Also you can use any clipboard format viewer to view what is actually stored in clipboard by different applications.
For example, all modern browsers and all Microsoft Office suite applications store in clipboard actual document location in HTML Format as simple plain text:
Version:1.0
StartHTML:000000271
EndHTML:000008359
StartFragment:000008219
EndFragment:000008255
StartSelection:000008219
EndSelection:000008255
SourceURL:http://stackoverflow.com/questions/42672385/copy-text-from-word-and-get-file-location-from-clipboard-c-sharp
...
You can't do this, I am afraid. This information is not made available in the clipboard.
Even if you listen to Ctrl + C and find an active instance of Word running, you still won't be 100% you get what you need. It might be a new document, which is not even saved yet on disk. Even more convoluted case: the user copies some text from an edit field on a dialog in Word.
I need a help in developing a Windows Appl using C#.NET VS2010. The functionality is very simple, the user will input a text file and my program is supposed to extract the relevant data from the text file and output it to either csv or text or whatever.
My biggest problem whenever I deal with text files is the format. Even though if you open the input text file in a Notepad or Wordpad it looks perfect, the layout etc. But once we start programming it I realize that what I am seeing is not the way the data is stored inside the file. I read many articles on Unicode/UTF etc.. etc.. but I dont have a definite solution to know exactly what my file format is. So the end result is that I end up getting many exceptions.
In Unix Shell Scripting it used to be simple. There is some good Unix command like less which is similar to more but it also display any formatting characters inside the file. Also there are some useful commands like unix2dos and dos2unix.
Nevertheless, is there some program/code or professional method which can find the exact file formatting of my input file and then reformat it to "plain text" so that the data extraction becomes easy and bug-free.
Thanks
Using the NeatUpload file-upload control
Is there a way I can paste a file path (instead of browsing) into an InputFile control?
Say I have the path on the clipboard and javascript sets focus to the control, and the user manually pastes the clipboard contents using ctrl+v.
Right now, if I paste the clipboard, it doesn't seem to receive the file. That is, the textual path does not seem to get accepted into the control.
Now, I've found these thread:
Assign file path to FileUpload Control
and
How can I set path in the fileupload control on page load
, but I thought maybe since NeatUpload has such influence over the control that there was another way - say, if the user pasted the file-path into a text box, then I could have the file-path available to code-behind. Then, how would I get that path into the InputFile control? I've read the NeatUpload docs and searched the forums, but I still need some advice or examples.
Is there a way to be able to receive a paste event into the InputFile control? Or, is there a way to get the path from a textbox into the upload sequence code?
Due to security reasons, there is no way to set any of the settings for this type of control.
However, a workaround is this:
Add a javascript (A simple $('InputFileID').click(); will do nicely) function that will click the Browse button. This will open the file-browsing dialogue. Now the user can paste the clipboard right into the box in that dialogue.
There is an existing process that is writing to a text file on my site. Let's say the file is at http://www.mysite.com/addresses/addresses.txt
I have been able to successfully display the contents of the file in a text box using client.DownloadString, however I can't find a clear answer on how to append to the end of this text file and also to clear the contents of this file. This is a text file on my web server.
I'm working in C#. I do know the path to the file on the server at c:\inetpub\site\addresses\address.txt as well.
Any ideas on how to append or clear this file? Everything I seem to find on it is on windows forms and i don't use enough DotNet to know where to look.
Thanks!
Check out this Article CodeSnip: Read and Write Text Files with ASP.NET 2.0
System.IO.StreamWriter StreamWriter1 =
new System.IO.StreamWriter(Server.MapPath("test.txt"));
StreamWriter1.WriteLine(TextBox1.Text);
StreamWriter1.Close();
I am using the Clipboard object to play with data copied to the clipboard. Lets say I have a few applications from which I can copy data to the clipboard like Excel, Notepad, etc.
I want to know whether there is any function or any way to find out from where the data is captured in clipboard, whether it is coming from Excel or Notepad or from some unknown application.
I am using C# and .NET 2.0
If you are using SetClipboardViewer api to detect when something is copied to the clipboard and processing WM_DRAWCLIPBOARD message then you can use GetClipboardOwner function to find handle to the window which initiated the operation. Using the handle you can retrieve the process id and path of the executable.
Based on the Clipboard class reference: http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.aspx
You cannot tell exactly which application the content in the clipboard comes from.
You can make some sort of guess work though.
E.g. From the Clipboard.ContainsText Method (TextDataFormat), you can tell if it's an app that outputs/displays HTML, Text, RTF etc.
See http://msdn.microsoft.com/en-us/library/system.windows.forms.textdataformat.aspx
Other than that, I doubt you can go further.