how to open listview window explorer in listview control - c#

i have a listview window browser thats working completely fine .i open folder through folder browser and the files and folders in that particular directory opens in the listview via using
PopulateListView(path)
now in my mouse double click event im opening a particular file and folder it opens the file but when it opens the directory a new window pops up .i want that directory to b opened in the listview control...the code for this scenarioa is
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
string pathdoubleClicked = listView1.FocusedItem.Tag.ToString();
PopulateListView(pathdoubleClicked);
Process.Start(pathdoubleClicked);
simpleStack.Push(pathdoubleClicked);
}
now i want to do it with if else like if the path is of drectory then go to populatelistview method other wise process.start but its now working any idea how can i do this

From what I understand, if the path is a directory, you want to display its content on double-click. If it's a file, you want to open it.
So you would simply do:
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
string pathdoubleClicked = listView1.FocusedItem.Tag.ToString();
if (System.IO.Directory.Exists(pathdoubleClicked))
{
PopulateListView(pathdoubleClicked);
}
else
{
Process.Start(pathdoubleClicked);
}
// ?
simpleStack.Push(pathdoubleClicked);
}

Related

How to create a ASPX file after clicking a button on another form

Hopefully this is clear enough, i have this bit of code :
private void BtnAdd_ServerClick(object sender, EventArgs e)
{
var path = #"C:\Users\User\Desktop\Demo\Demo\" + BtnName.Value;
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
That creates a folder named after the value of a text box, and i need to know if there's a way to create an aspx file the same way, and save it in one of those folders or anywhere it just needs to be accessible to the project, thanks in advance! I'm open to any questions or code updates.

Checking if a file exists on your computer

Basically i have a list of folder paths on XML File. I created a dataGrid View which reads this XML file and displays the list of folders in the XML into the data Grid View. Now I need to create a way where the user chooses a folder path from one of the list I have and the program will check if this folder exists on the computer being used.Is there a way to create this program?
Try Button with event handler for the click event and assuming that your input textbox is named textBoxForPath this should work:
private void Button1_Click(object sender, EventArgs e)
{
string path = this.textBoxForPath.Text;
if (File.Exists(path))
{
// Do Something
}
}

how i can insert an image in web browser control in c# with out open image ui?

I have a web browser control in C# that it's design mode is on. I use it to make a (WYSIWYG) HTML editor. I want to insert a photo on this without UI, when user wants to insert image I show to him/her a window that shows on it some known name for user. Then with search (s)he find her/his photo and add it to control.
this is my open image form:
Photos are in database and user only know them with names. I upload all of them in a folder and show above list to user and user selects a picture. I want to add image by it's location in hard disk and allow user to set its alignment .
How I can do this ?
Adding a new element to a document is very logical. The first step is to create the node (element) you wish to append, the next is to find where you wish to append it within the document, and the final step is to actually do the appending.
I write an Example for you:
private void Form1_Load_1(object sender, EventArgs e)
{
webBrowser1.DocumentText = "<html><body></img></body></html>";
}
private void insert_image_btn_Click(object sender, EventArgs e)
{
HtmlElement userimage = webBrowser1.Document.CreateElement("img");
userimage.SetAttribute("src", "image location");
userimage.Id = "imageid";
webBrowser1.Document.Body.AppendChild(userimage);
}
private void btn_set_aliign_Click(object sender, EventArgs e)
{
webBrowser1.Document.GetElementById("imageid").SetAttribute("float", "right");
}

Load winforms icon from folder dynamically

I need to change the winform icon to an icon found in a directory. This needs to work in the same way a web browser handles the loading of website icons.
If this is going to be dynamic you can use a FileSystemWatcher and monitor the created and changed events in your Folder for your file changes.
private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
{
if (e.Name == "myIcon.ico")
{
this.Icon = new Icon(e.FullPath);
}
}
Set Icon property in constructor or Load event of form (make sure that icon exist in application directory):
Icon = new Icon("favicon.ico");

File Upload in C# windows Application

In my C# Windows application I want to upload a pdf file but in my toolbox I cannot find a FileUpload control.
How can I go about and uploading a pdf file in a C# windows application.?
regards
After you put a OpenFileDialog control on your form, let's say that you click a button and:
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK) // Test result.
{
//Do whatever you want
//openFileDialog1.FileName .....
}
}
it goes something like this :-)
You can use OpenFileDialog to get the filename of the file you need and then .NET File object to read data from the file. You might need a control being able to display a PDF file. Please read the following:
Viewing PDF in Windows forms using C#

Categories