Reputation: 95
I am making an application called Profiler to store some people's profiles, and will use a database to store the profile photo's path.
This is my FindPhoto
button (to upload the profile photo):
private void btnFindPhoto_Click(object sender, EventArgs e)
{
ofdFindPhoto.Title = "Select a Photo ";
ofdFindPhoto.InitialDirectory = @"D:\Desktop";
ofdFindPhoto.FileName = "";
ofdFindPhoto.Filter = "JPEG Image|*.jpg|GIF Image|*.gif|PNG Image|*.png|BMP Image|*.bmp";
ofdFindPhoto.Multiselect = false;
if (ofdFindPhoto.ShowDialog() != DialogResult.OK) { return; }
// Show the recently uploaded photo on profile
picProfilePhoto.ImageLocation = ofdFindPhoto.FileName;
}
When the user clicks the button to save the profile, I get the txtName.Text, txtPhone.Text, txtDescription.Text and photo path to save to the database. I want to use something like this to save the photo path:
string photoPath = Application.StartupPath + @"\Photos\" + txtName.Text +
Path.GetExtension(ofdFindPhoto.FileName);
This should generate some path like:
Drive:\InstalledPath\Profiler\Username.jpg (or whatever extension)
In short, I need to place a folder inside the application's root, but this folder should be created on install or first run (preferably that I can use on debug, too).
Upvotes: 0
Views: 5656
Reputation: 2399
try this in program.cs.It checks for folder when the application in opened
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Profiles"))
{
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Profiles");
}
Application.Run(new form1());
Upvotes: 1
Reputation: 142038
if(!Directory.Exists(Application.StartupPath + @"\Photos"))
Directory.CreateDirectory(Application.StartupPath + @"\Photos");
Upvotes: 2