I would like to have a text box in my C # web application if the file exists on the server. Any ideas? New in C # here. For example, if I have text.txt (and I know that it will always be text.txt), that someone gets into a folder on a file server, my web application page alerts me using a timer (or something in like that).
The best way to check if one particular file exists is File.Exists:
if (File.Exists("c:\\test.txt")) //inform user
- -, , , - . , .
(.. -, -). JavaScript; , alert.
: JavaScript , . , JavaScript (setInterval), AJAX. "" - .aspx , HTML (, , "0" "1" ), , . JavaScript , , .
, AJAX, , jQuery. , , , , AJAX.
For this purpose you can use the FileSystemWatcher class . But this should run as a client application (Windows Forms application or service), and not from a web application (you cannot access the client computer from your browser).
try it
string path = "C:\\TestFolder\\......."; // Path DirectoryInfo directory = new DirectoryInfo(path); foreach (FileInfo file in directory.GetFiles()) { if (file.Name == text.txt) { MessMessageBox.Show("Text file exists"); } }
Hope this helps
// TODO: Read up on FileSystemWatcher FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = @"C:\MyDirectory"; watcher.Changed += new FileSystemEventHandler(watcher_Changed); watcher.Deleted += new FileSystemEventHandler(watcher_Deleted); watcher.Renamed += new RenamedEventHandler(watcher_Renamed) watcher.Created += new FileSystemEventHandler(watcher_Created); watcher.EnableRaisingEvents = true; watcher.Filter = "*.txt"; // could also set it to "text.txt" or "*" void watcher_Changed(object sender, System.IO.FileSystemEventArgs e)) { MessageBox.Show("Zomg " + e.FullPath +" has been changed!!"); } private void fileWatcher_Renamed(object sender, System.IO.RenamedEventArgs e) { MessageBox.Show(e.OldFullPath + " was renamed to " + e.FullPath); } private void fileWatcher_Deleted(object sender, System.IO.FileSystemEventArgs e) { MessageBox.Show(e.FullPath + " was deleted!"); } private void fileWatcher_Created(object sender, System.IO.FileSystemEventArgs e) { MessageBox.Show(e.FullPath + " was created!"); }
Source: https://habr.com/ru/post/1792014/More articles:WordPress: count all user comments and then count metadata by comments - commentsDistinguish single and double click - javascriptОператоры выбора для генетических алгоритмов - artificial-intelligencehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1792012/redirect-io-of-process-to-windows-socket&usg=ALkJrhj3BbUaQN108xEEJrHgqHlEuElssggetting java.lang.IllegalArgumentException: Invalid pattern character 'o'? when parsing java.text.SimpleDateFormat - javaUnix behavior with two different processes containing a descriptor in one file and one process deleting a file - unixWhat is the basic AOP design model? - designPear Queue - Logs / Records? - phpCherryPy 60x as slow in test with 8 requesting threads versus 7 - pythonUsing OpenGL to display a 2D map or not? (Android 3.0 SDK) - androidAll Articles