Sign up
Login
New
Trending
Archive
English
English
Sign up
Login
New Paste
Add Image
using System; using System.IO; using System.Windows.Forms; namespace drop_location { public partial class Form1 : Form { // Add OpenFileDialog to the form class private OpenFileDialog openFile = new OpenFileDialog(); public Form1() { InitializeComponent(); // Optional: Configure the OpenFileDialog openFile.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; openFile.Title = "Select a File"; } // The GetFileName method gets a filename from the user private bool GetFileName(out string selectedFile) { if (openFile.ShowDialog() == DialogResult.OK) { selectedFile = openFile.FileName; return true; } else { selectedFile = ""; return false; } } // The LoadFileContents method loads file contents into the ListBox private void LoadFileContents(string filename) { try { string lineContent; // Clear the ListBox first listBox1.Items.Clear(); // Read the file using (StreamReader inputFile = File.OpenText(filename)) { while (!inputFile.EndOfStream) { lineContent = inputFile.ReadLine(); // Only add non-empty lines (optional) if (!string.IsNullOrWhiteSpace(lineContent)) { listBox1.Items.Add(lineContent); } } } // Optional: Show success message or update status if (listBox1.Items.Count > 0) { MessageBox.Show($"Successfully loaded {listBox1.Items.Count} items.", "File Loaded", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("The file is empty.", "No Data", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show($"Error loading file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { // Optional: Add functionality when an item is selected if (listBox1.SelectedItem != null) { // For example, display the selected item in a label or textbox // labelSelectedItem.Text = $"Selected: {listBox1.SelectedItem}"; } } private void button1_Click(object sender, EventArgs e) { // Load file button click string filename; if (GetFileName(out filename)) { LoadFileContents(filename); } } private void button2_Click(object sender, EventArgs e) { this.Close(); } private void Form1_Load(object sender, EventArgs e) { // Optional: Initialize form properties listBox1.SelectionMode = SelectionMode.One; // Set button text for clarity button1.Text = "Load File"; button2.Text = "Exit"; // Optional: Set form title this.Text = "Drop Location - File Viewer"; } // Optional: Add method to clear the ListBox private void ClearListBox() { listBox1.Items.Clear(); } // Optional: Add method to save ListBox contents to a file private void SaveListBoxContents() { SaveFileDialog saveFile = new SaveFileDialog(); saveFile.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; saveFile.Title = "Save ListBox Contents"; if (saveFile.ShowDialog() == DialogResult.OK) { try { using (StreamWriter outputFile = new StreamWriter(saveFile.FileName)) { foreach (var item in listBox1.Items) { outputFile.WriteLine(item.ToString()); } } MessageBox.Show("File saved successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show($"Error saving file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } // Optional: Add a third button for saving private void button3_Click(object sender, EventArgs e) { SaveListBoxContents(); } } }
Settings
Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English