Errors and more erros

spicyadmin

Member
Joined
Dec 23, 2021
Messages
15
Programming Experience
Beginner
I've been trying to find a solution to a problem I am having. I am trying to save a picture to the "My Pictures" folder but I keep getting an error in the code saying "cannot convert from 'string' to 'system.environment.specialfolderoption'"

What I have:
pbx_image.Image.Save(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures, "Capture-" + DateTime.Now.ToString("HH-mm-ss tt") + ".jpg"));
 
GetFolderPath doesn't accept a string as second parameter.
 
Fix your GetFolderPath call.
 
This is what I recommend you do, break your single line mess that doesn't work into separate lines.
In one line call GetFolderPath method and assign the result to a variable.
In another add the filname string.
Finally when you have a string that is a valid path you can call Save method.
 
Now I am getting "cannot convert from 'string' to 'System.Drawing.Imaging.ImageFormat'"
C#:
            string imgs = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);

            pbx_image.Image.Save(imgs, "IPCams Capture-" + DateTime.Now.ToString("HH-mm-ss tt") + ".jpg");
 
That is a different error. Next step is completing the file path in line 2. I recommend Path.Combine method to combine the folder and the filename, assign the result to a variable like you did in line 1.
 
That is a different error. Next step is completing the file path in line 2. I recommend Path.Combine method to combine the folder and the filename, assign the result to a variable like you did in line 1.
Not too sure how I would use the Path.Combine method
I am still getting the same error now with the following

C#:
        private void btn_capImage_Click(object sender, EventArgs e)
        {
            string imgs = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);

            string saves = ("IPCams Capture-" + DateTime.Now.ToString("HH-mm-ss tt") + ".jpg");

            pbx_image.Image.Save(imgs, saves);
        }
 
The first parameter is supposed to be the fullpath name to the file where you want to save. The second parameter is what file format you want to use. This documentation shows why the compiler gave you that error you were seeing in post #9 where it was complaining about the second parameter being the wrong type.

Part of learning to write code is learning how to read the documentation -- unless you just want to be a copy-and-paste programmer who just looks things up in StackOverflow and other sites, cobbles them together and gets other people to help figure out why the cobbling together is not working.
 
The first parameter is supposed to be the fullpath name to the file where you want to save. The second parameter is what file format you want to use. This documentation shows why the compiler gave you that error you were seeing in post #9 where it was complaining about the second parameter being the wrong type.

Part of learning to write code is learning how to read the documentation -- unless you just want to be a copy-and-paste programmer who just looks things up in StackOverflow and other sites, cobbles them together and gets other people to help figure out why the cobbling together is not working.
I don't want to be a copy and paste programmer, but I am seriously having trouble understanding the documentation
 
Let's try attacking this a different way. Why do you think that the code in post #9 should succeed? Explain how to you came about to writing line #7.
 

Latest posts

Back
Top Bottom