After some information about C#

Page 1 of 1

9 Replies - 398 Views - Last Post: 08 July 2012 - 07:04 AM Rate Topic: -----

#1 burgo857  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 02-June 12

After some information about C#

Posted 07 July 2012 - 07:42 PM

Hi all,

I am currently working on a new project and was wondering even if i use the resources folder withing c# for files and folders can i still just use the application in the bin folder?

I really do not want to have to make people install the application as its not like its a huge project, it just updates a few files for a game and it would just be a waste of time having to make someone install it just for that...
Is This A Good Question/Topic? 0
  • +

Replies To: After some information about C#

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3475
  • View blog
  • Posts: 10,721
  • Joined: 05-May 12

Re: After some information about C#

Posted 07 July 2012 - 08:32 PM

Resources get compiled into an assembly that is put into your bin folder (and/or subfolders if you have multiple languages). To "deploy" your program, all you need to give out is your executable, and the resource assembly if the resources were compiled into a resource assembly. I forget now, but there is a way to tell Visual Studio to put the fallback language resources into your executable instead of the resource assembly. That way you can get by with "xcopy deployment" for your executable.

But don't take my word for it, try copying your .EXE into another machine or another folder and see what works (or doesn't work).
Was This Post Helpful? 0
  • +
  • -

#3 burgo857  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 02-June 12

Re: After some information about C#

Posted 07 July 2012 - 08:56 PM

Oooh yeah,

Thanks mate. I was thinking about that as well... I know Visual Basic 6 did this ill have a look for C#. Also i thought this would make a anti-virus detect the program to have a hack in it because i would have added some dll files to the exe?

I guess i can always try.

Thankyou.
Was This Post Helpful? 0
  • +
  • -

#4 burgo857  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 02-June 12

Re: After some information about C#

Posted 07 July 2012 - 10:02 PM

So, how would you actually define a files location in the resource folder?

I am moving and replacing a file but i do not know how to define the resources location?

                    //Move file1
                    if (File.Exists(@"C:\users\test.txt"))
                        {
                            File.Delete(@"C:\users\test.txt");
                        }
                    File.Move(WHERE_IS_RESOURCES_LOCATION, @"C:\users\");

Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3475
  • View blog
  • Posts: 10,721
  • Joined: 05-May 12

Re: After some information about C#

Posted 07 July 2012 - 11:47 PM

Your resources should be in the same directory (or a child if using satellite assemblies) as your application. See Application.StartupPath.
Was This Post Helpful? 0
  • +
  • -

#6 burgo857  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 02-June 12

Re: After some information about C#

Posted 08 July 2012 - 12:02 AM

View PostSkydiver, on 07 July 2012 - 11:47 PM, said:

Your resources should be in the same directory (or a child if using satellite assemblies) as your application. See Application.StartupPath.


In C# when i click the resources folder, i can find a file eg test.png if i clicked test.png and changed its build action to embedded resource couldnt i use my previous posted code and just somehow define the location of the image?

and use
File.Move(Properties.Resources.test.png, @"C:\users\test.png");
?

if that would work then can i have a folder inside resources which i can also somehow include it?
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3475
  • View blog
  • Posts: 10,721
  • Joined: 05-May 12

Re: After some information about C#

Posted 08 July 2012 - 12:10 AM

No. When you embed a resource, the resource data is made into binary blob that is stored in the assembly. You'll have to stream the data out of the blob and write it to it's intended destination. You can't use File.Move().
Was This Post Helpful? 1
  • +
  • -

#8 burgo857  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 02-June 12

Re: After some information about C#

Posted 08 July 2012 - 12:42 AM

Oooooh goodness!

I am only new to C#... How do i do that mate?
Was This Post Helpful? 0
  • +
  • -

#9 burgo857  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 02-June 12

Re: After some information about C#

Posted 08 July 2012 - 01:18 AM

I am making a C# Form App.

When you click a button i want it to check if a directory exists, if directory exists it deletes specified files/folders and then moves new files embedded to the application to the specified location on the computer.


How can i do this?

i tried the following:
        private void button2_Click(object sender, EventArgs e)
        {
            if (File.Exists(@"C:\users))
                {
                    //Move test.exe
                    if (File.Exists(@"C:\users\test.exe"))
                        {
                            File.Delete(@"C:\users\test.exe");
                        }
                    File.Move(PATH_TO_EMBEDDED_RESOURCE, @"C:\users\");
                }
            else
            {
                MessageBox.Show("Can not find C:\users\. Make sure you have this folder location.",
                "Error",
                MessageBoxButtons.OK,
                MessageBoxIcon.Error,
                MessageBoxDefaultButton.Button1);
            }
        }


I am getting really frustrated with this i have now spent 2 days trying to find a solution on forums, Google etc. Is their a way to do this? please!

Also i am new to C# which is why im frustrated and having trouble so please use simple responses.
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,662
  • Joined: 02-June 10

Re: After some information about C#

Posted 08 July 2012 - 07:04 AM

You should rename your GUI controls before doing things with them:
btnMove_Click is a lot more maintainable and understandable than button2_Click

(@"C:\users\test.exe");
You shouldn't be trying to put files loose in the Users directory. Either put it in the current user's home directory (Bob\Documents\text.exe) or in the user's ApplicationData directory. You don't own the user's computer so you don't have the right to clutter it up as you like. You need to stick to accepted locations and ways of doing things.

You shouldn't be making assumptions about other people's computers. The user may not have a C drive, or it may not be their boot drive with the users directory. You should use the dynamic SpecialFolders enumeration.

03 if (File.Exists(@"C:\users))
c:\users\ is a folder, not a file. Therefore it will never match your File.Exists check



10 File.Move(PATH_TO_EMBEDDED_RESOURCE, @"C:\users\");
Its an embedded resource. Not a file. It does not have a path. It exists in memory as part of the application. You can't use calls to the OSes file system to move it. You are going to have to save it.

Stop trying to architect a program while you are still learning the basics of C#. It just never works. Its like saying you are going to learn home architecting WHILE you hammer boards together without a blueprint, and try to learn both new skills at the same time.

First learn the language. Do a couple hundred tutorial projects where you build what you're told to build, the way you are told to build it WITH AN EXPLANATION OF WHY so you can learn.

Then later you can start architecting your own simple stuff. Build a calculator. Build a DVD library program. Etc. Stuff that doesn't involve the complexity of a game.

Then move up to games.



There are three routes people seem to take when learning programming.
  • Just start trying to create programs
  • Start taking apart other programs and try to figure out the language by reverse engineering
  • Follow a guided learning course (school or self-teaching books)


For the life of me I can't figure out why people try 1 & 2. I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

Quote

Where do I start?


You start by learning a coding language FIRST.
Learn to plan before you type.
THEN you start designing software with a purpose.


If this sounds like you

Newbie/Rookie said:

I have a little programming experience but I need to write ...
read this section
Spoiler


Otherwise, you can just jump to the resources here:
Some of the tutorials below are for C# or Java not C, C++, VB.NET [...]. But the conceptual stuff of classes, object oriented design, events etc. are not language specific and should give you enough guidance in theory of program development for you to be able to look-up specific code example in your chosen coding language.



Resources, references and suggestions for new programmers. - Updated Mar 2012
Spoiler






08 File.Delete(@"C:\users\test.exe");
The fact that you're looking to delete executables on the user's drive, don't want to make an installer, and want to replace files from resources hidden within your executable make me STRONGLY think this is a case of you wanting to install some kind of malware.




Was This Post Helpful? 0
  • +
  • -

Page 1 of 1