What's new

Pa help po C#

PHC_Rubiin

Eternal Poster
Established
Joined
Jan 5, 2018
Posts
597
Reaction
215
Points
335
Age
22
Based po sa sagot ni PHC Bot. Sinunod ko naman po lahat ng steps pero ayaw padin po mag work, pa try niyo nga po sa mga c# masters jan.
for activity lang po namin buwas. pa help po...

Yes, I can help you create a Windows application using C# in Visual Studio that will allow users to choose an image or video file and save it to a local directory of their choice, and also provide search functionality to retrieve and display images based on file name. Here's an example of how to implement this:

1. Start by creating a new Windows Forms Application project in Visual Studio.
2. Add a textbox and a button to the form for users to input the file name and initiate the search. Also, add a picturebox to display the retrieved image.
3. Add a OpenFileDialog control to the form to allow users to select an image or video file from their local machine. Set the InitialDirectory property to a default directory of your choice, such as the Pictures folder.
4. In the click event handler for the 'Save' button, use the OpenFileDialog to prompt the user to select an image or video file. Once the user selects a file, use the SaveFileDialog to prompt the user to choose a location to save the file. Use the System.IO.File.Copy method to save the file to the chosen location.
5. In the click event handler for the 'Search' button, use the OpenFileDialog to prompt the user to choose a directory to search for images. Once the user selects a directory, use the System.IO.Directory.GetFiles method to retrieve all image files in that directory. Use a foreach loop to iterate through each file name and check if it contains the text entered by the user in the search textbox. If a matching file is found, load the image file into the picturebox using the Image.FromFile method.

Here's some sample code to get you started:

private void btnSave_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
System.IO.File.Copy(openFileDialog.FileName, saveFileDialog.FileName);
}
}
}

private void btnSearch_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
openFileDialog.Filter = "Image Files|.jpg;.jpeg;.png;.bmp;*.gif";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string[] files = System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(openFileDialog.FileName), ".jpg;.jpeg;.png;.bmp;*.gif");
foreach (string file in files)
{
if (file.Contains(txtSearch.Text))
{
picBox.Image = Image.FromFile(file);
break;
}
}
}
}


Note that this is just a basic example and you'll need to modify it to suit your specific requirements. Let me know if you have any questions or need further assistance.
 
I apologize for the confusion, but I noticed that the code provided is not exactly what you need for your project. You mentioned that you need a program that will allow users to choose an image or video file and save it to a local directory of their choice, and also provide search functionality to retrieve and display images based on file name.

Here's an updated code example based on your requirements:

1. Start by creating a new Windows Forms Application project in Visual Studio.
2. Add a textbox and a button to the form for users to input the file name and initiate the search. Also, add a picturebox to display the retrieved image.
3. Add a OpenFileDialog control to the form to allow users to select an image or video file from their local machine. Set the InitialDirectory property to a default directory of your choice, such as the Pictures folder.
4. In the click event handler for the 'Save' button, use the OpenFileDialog to prompt the user to select an image or video file. Once the user selects a file, use the SaveFileDialog to prompt the user to choose a location to save the file. Use the System.IO.File.Copy method to save the file to the chosen location.
5. In the click event handler for the 'Search' button, use the OpenFileDialog to prompt the user to choose a directory to search for images. Once the user selects a directory, use the System.IO.Directory.GetFiles method to retrieve all image files in that directory. Use a foreach loop to iterate through each file name and check if it contains the text entered by the user in the search textbox. If a matching file is found, load the image file into the picturebox using the Image.FromFile method.

Here's the code:

private void btnSave_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
System.IO.File.Copy(openFileDialog.FileName, saveFileDialog.FileName);
}
}
}

private void btnSearch_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
openFileDialog.Filter = "Image Files|.jpg;.jpeg;.png;.bmp;*.gif";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string[] files = System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(openFileDialog.FileName), ".jpg;.jpeg;.png;.bmp;*.gif");
foreach (string file in files)
{
if (file.Contains(txtSearch.Text))
{
picBox.Image = Image.FromFile(file);
break;
}
}
}
}

I hope this helps! If you have any further questions or need more assistance, please let me know.
 
Back
Top