C# Add File Selected using OpenFileDialog1 to Resources

DavidRO99

Average Ryzen user.
OP
Member
Joined
Jun 11, 2016
Messages
1,018
Trophies
0
Age
26
Location
your back-door
XP
948
Country
Korea, North
So, if you check the PS3 Forums you may see that I made a mod menu named Project FaZe. That mod menu also has a custom program. The problem is that I made the custom program in such a way that it contains the actual mod menu inside the Resources and I would like to make a way to add any mod menu file to Resources using OpenFileDialog1. Easy just throw some code together and... error. Can any of you talented people help me find the error?

Code:
private void materialFlatButton4_Click_1(object sender, EventArgs e)
    {
        openFileDialog1.Title = "Open GSC File";
        openFileDialog1.Filter = "GSC|*.gsc";
        string fileName = "_development_dvars.gsc";
        fileName = openFileDialog1.FileName;
        openFileDialog1.FileName = "";
        openFileDialog1.InitialDirectory =     System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        openFileDialog1.ShowDialog();
        openFileDialog1.FileName = Project_FaZe_Injector.Properties.Resources._development_dvars;
    }
 

BeySW

New Member
Newbie
Joined
Jul 28, 2016
Messages
1
Trophies
0
Location
Oklahoma
XP
41
Country
United States
So, if you check the PS3 Forums you may see that I made a mod menu named Project FaZe. That mod menu also has a custom program. The problem is that I made the custom program in such a way that it contains the actual mod menu inside the Resources and I would like to make a way to add any mod menu file to Resources using OpenFileDialog1. Easy just throw some code together and... error. Can any of you talented people help me find the error?

Code:
private void materialFlatButton4_Click_1(object sender, EventArgs e)
    {
        openFileDialog1.Title = "Open GSC File";
        openFileDialog1.Filter = "GSC|*.gsc";
        string fileName = "_development_dvars.gsc";
        fileName = openFileDialog1.FileName;
        openFileDialog1.FileName = "";
        openFileDialog1.InitialDirectory =     System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        openFileDialog1.ShowDialog();
        openFileDialog1.FileName = Project_FaZe_Injector.Properties.Resources._development_dvars;
    }

To begin, the code sets the filename and then clears it.
Anyway, try this, though I'm not too sure what you are trying to do.
The code is very well commented.

Code:
private static void materialFlatButton4_Click_1(object sender, EventArgs e)
{
    // Prompt user to open file
    OpenFileDialog open = new OpenFileDialog
    {
        Title = "Open GSC File",
        Filter = "GSC|*.gsc",
        FileName = "_development_dvars.gsc"
    };

    // If user clicks cancel, return.
    if (open.ShowDialog() != DialogResult.OK)
        return;

    // As the file is an embedded resource, extract it to the Windows %TEMP% directory.
    string fileName = Path.GetTempPath() + "_development_dvars.gsc"; // Full path & file name.
    byte[] developmentDvars = Resources._development_dvars;  // Extract resource file.
    File.WriteAllBytes(fileName, developmentDvars);  // Copy it as a file to the temp directory.

    // we know the above created our file but we check, just in case.
    if (File.Exists(open.FileName))
    {
        // At this point, the file is open.
        // TODO: Process file here..
    }
}
 

DavidRO99

Average Ryzen user.
OP
Member
Joined
Jun 11, 2016
Messages
1,018
Trophies
0
Age
26
Location
your back-door
XP
948
Country
Korea, North
To begin, the code sets the filename and then clears it.
Anyway, try this, though I'm not too sure what you are trying to do.
The code is very well commented.

Code:
private static void materialFlatButton4_Click_1(object sender, EventArgs e)
{
    // Prompt user to open file
    OpenFileDialog open = new OpenFileDialog
    {
        Title = "Open GSC File",
        Filter = "GSC|*.gsc",
        FileName = "_development_dvars.gsc"
    };

    // If user clicks cancel, return.
    if (open.ShowDialog() != DialogResult.OK)
        return;

    // As the file is an embedded resource, extract it to the Windows %TEMP% directory.
    string fileName = Path.GetTempPath() + "_development_dvars.gsc"; // Full path & file name.
    byte[] developmentDvars = Resources._development_dvars;  // Extract resource file.
    File.WriteAllBytes(fileName, developmentDvars);  // Copy it as a file to the temp directory.

    // we know the above created our file but we check, just in case.
    if (File.Exists(open.FileName))
    {
        // At this point, the file is open.
        // TODO: Process file here..
    }
}
Im trying to copy the file that the user selected to the Resources of the application :) You are doing the exact opposite
 

evandixon

PMD Researcher
Developer
Joined
May 29, 2009
Messages
1,725
Trophies
1
Website
projectpokemon.org
XP
2,332
Country
United States
Resources are generally read-only. If you want to change them, it would be best to store them elsewhere. Perhaps copy from the resources to the Current User App Data if the file doesn't exist there, and have your dialog alter the resources there?
 

DavidRO99

Average Ryzen user.
OP
Member
Joined
Jun 11, 2016
Messages
1,018
Trophies
0
Age
26
Location
your back-door
XP
948
Country
Korea, North
Resources are generally read-only. If you want to change them, it would be best to store them elsewhere. Perhaps copy from the resources to the Current User App Data if the file doesn't exist there, and have your dialog alter the resources there?
The problem is that I don't know how to make a custom resources file so it can read from a folder that I would include with the exe
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    The Real Jdbye @ The Real Jdbye: