Extracting File from the Resources.

Code needed ~ Help obvious in the other words...

Page 1 of 1

11 Replies - 1871 Views - Last Post: 21 August 2010 - 05:35 AM Rate Topic: -----

#1 SourLemons  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 65
  • Joined: 02-August 10

Extracting File from the Resources.

Posted 20 August 2010 - 11:53 AM

Alright, I am a beginner here. I am a C# user,in VS 2010 to be precise.

I've a problem following a code. It is about extracting a file from the Resources to a specific folder.

_Because of an incomplete knowledge, I couldn't figure out a way to surpass and learn the extracting code.

The code I couldn't use in VS 2010 ,C# is as follows.

            byte[] myfile = Properties.Resources.修改IP;
            FileDialog.WriteAllBytes(textBox1.Text + "\\修改IP.exe", myfile);
            MessageBox.Show("Your basic tools has been extracted! ", "Basic Tools Extraction", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            Process myproc = new Process();
            myproc.StartInfo.FileName = textBox1.Text + "\\修改IP.exe";
            myproc.Start();




Posted Image

So, that is what I need help with. It shows some error because the guide was in C# 2005, VS 2005.

Posted Image

And here is the link to that video which i was following..



Please consider this post very important matter to me, a learner and try to help me. This might be because of my wrong doings or it is what it is.

Thanks and Please.

Is This A Good Question/Topic? 0
  • +

Replies To: Extracting File from the Resources.

#2 tlhIn`toq  Icon User is offline

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

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: Extracting File from the Resources.

Posted 20 August 2010 - 12:01 PM

Quote

It shows some error


Run the project again, only this time write down the error and what line the error is on. We can't help you track down "some error".

You should probably also go over this Debugging tutorial to learn some techniques for debugging.
Was This Post Helpful? 0
  • +
  • -

#3 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Extracting File from the Resources.

Posted 20 August 2010 - 12:03 PM

For example, if I have an image called Penguins.jpg in my project resources, I can then save it somewhere else like this:

Bitmap bmp = Properties.Resources.Penguins;
bmp.Save(@"D:\Temporary\image.jpg");


Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

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

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: Extracting File from the Resources.

Posted 20 August 2010 - 12:10 PM

I understand your goal.

What is the error message you get?
Was This Post Helpful? 0
  • +
  • -

#5 SourLemons  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 65
  • Joined: 02-August 10

Re: Extracting File from the Resources.

Posted 20 August 2010 - 12:30 PM

I can't exactly say what the error message is because the problem is that i can't even debug.

It is because of the code. I have a feeling that the code i wrote is wrong or not valid in VS 2010. Else way, I might be doing it wrong. :whatsthat:

Posted Image

If you still can't understand. The picture talks a bit?

Posted Image

Ty and Ty for the debugging tutorial.

This post has been edited by SourLemons: 20 August 2010 - 12:32 PM

Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

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

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: Extracting File from the Resources.

Posted 20 August 2010 - 12:51 PM

Quote

I can't exactly say what the error message is because the problem is that i can't even debug.
Why not?


Quote

It is because of the code.
Of course its because of the code. Everything we do is because of the code... because we write code for a living. I never once thought it was because of a hamburger or because of a dead battery on the car. Of course it is because of the fraking code. Duh.

Looking at your photos there doesn't seem to be anything wrong with the code itself, aside from the screwy asian characters.

Stop showing us the code and show us the errors that Visual Studio is reporting. Last chance before I unsubscribe from this thread.
Was This Post Helpful? 0
  • +
  • -

#7 SourLemons  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 65
  • Joined: 02-August 10

Re: Extracting File from the Resources.

Posted 20 August 2010 - 01:08 PM

Firstly sorry for pissing you off and for the low graphics of the video. :sweatdrop:

Video here. Watch it in full screen if you really are watching.



Picture if you were talking about error statements then,

Posted Image

If i am still wrong, still ain't understanding then please forgive me. :whatsthat:
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

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

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: Extracting File from the Resources.

Posted 20 August 2010 - 01:31 PM

  • The type or namespace 'process' could not be found. Are you missing a reference?
  • System.Windows.Forms.FileDialog does not have a definition for "WriteAllBytes"
  • The resource named "Launcher's Banner" is not a valid identifier.


Ok. Now we have errors. And really basic, self explanitory errors.


System.Windows.Forms.FileDialog does not have a definition for "WriteAllBytes"
There is no method built into a FileDialog named "WriteAllBytes". It doesn't exist.
So your line
FileDialog.WriteAllBytes("\\gibberish.exe", IP);

Is calling a function that doesn't exist.

The type or namespace 'process' could not be found. Are you missing a reference?
Process is part of System.Diagnostics;
You need to include a using statement or fully qualify your use if process.
using System.Diagnostics;

or
System.Diagnostics.Process myProc = new System.Diagnostics.Process();


The resource named "Launcher's Banner" is not a valid identifier.
What can I say that the error message doesn't already say really plain and clear? Its not a valid name.

Let me make a suggestion: Start smaller. You obviously have little experience with C#. There's nothing wrong with that. We all started at square one. But you need to work out how to crawl before you can run. In this case you need to work out how to resolve simple errors that are well explained, before you should be dabbling with complex issues like resources.
Was This Post Helpful? 0
  • +
  • -

#9 SourLemons  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 65
  • Joined: 02-August 10

Re: Extracting File from the Resources.

Posted 20 August 2010 - 01:55 PM

So, Isn't there a way you could help me with it? ( correcting the code if possible )

Anyways, Thank Q for figuring out the problem. :whatsthat:
Was This Post Helpful? 0
  • +
  • -

#10 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Extracting File from the Resources.

Posted 20 August 2010 - 02:21 PM

Did you try what I've shown in my previous post?

Also, WriteAllBytes is called from File (member of the System.IO namespace).
Was This Post Helpful? 0
  • +
  • -

#11 tlhIn`toq  Icon User is offline

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

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: Extracting File from the Resources.

Posted 20 August 2010 - 02:36 PM

Quote

So, Isn't there a way you could help me with it? ( correcting the code if possible )

It's not my project. I'm not really interested in collaberating with someone on a project.

This isn't a case of fixing code. You need to *learn* how to debug your own code. Probably need to learn to *write* code rather than just copy/paste 10 different examples from web sites and think they will magically work together.

I will say again... Start smaller with tutorials.

I am going to guess that you are trying to teach yourself C# without much guidance, a decent book or without knowing where to look. Sometimes just knowing where to look can make all the difference. Google is your friend.
Search with either "C#" or "MSDN" as the first word:
"C# picturebox load image openfiledialog" Its all the key parts of your question
Any new control like a picturebox is fully explained on the MSDN with example code so this works: "MSDN Picturebox"

But honestly, just typing away and seeing what pops up in Intellisense is going to make your self-education take 20 years. You can learn by trying to reverse engineer the language through banging on the keyboard - or you can learn by doing the tutorials and following a good "How to learn C#" book.

May I suggest picking up a basic C# introductory book? It's not that people here don't want to be helpful, but there is a certain amount of basic learning work that one should really take upon themselves before asking for help. There are so many great "How do I build my first application" tutorials on the web... There are dozens of "Learn C# in 21 days", "My first C# program" books at your look book seller or even public library... Asking a forum, any forum, to hand-hold you through it is just redundant. In many ways it disrespects the people who have invested dozens of hours in the on-line tutorials and those that spent thousands of hours in authoring books.

Build a Program Now! in Visual C# by Microsoft Press, ISBN 0-7356-2542-5
is a terrific book that has you build a Windows Forms application, a WPF app, a database application, your own web browser.

C# Cookbooks
Are a great place to get good code, broken down by need, written by coding professionals. You can use the code as-is, but take the time to actually study it. These professionals write in a certain style for a reason developed by years of experience and heartache.

Microsoft Visual Studio Tip, 251 ways to improve your productivity, Microsoft press, ISBN 0-7356-2640-5
Has many, many great, real-world tips that I use all the time.

The tutorials below walk through making an application including inheritance, custom events and custom controls.
Quick and easy custom events
Bulding an application - Part 1
Building an application - Part 2
Working with environmental variables

Writing a text file is always one of the first things people want to do, in order to store data like high-scores, preferences and so on
Writing a text file tutorial.

These are just good every-day references to put in your bookmarks.
MSDN C# Developers Center with tutorials
Welcome to Visual Studio

Have you seen the MSDN Code Samples? They spent a lot of time creating samples and demos. It seems a shame to not use them.

  • Anonymous Delegates: Demonstrates the use of unnamed delegates to reduce application complexity.
  • Arrays: Shows how to use arrays.
  • Attributes: Shows how to create custom attribute classes, use them in code, and query them through reflection.
  • Collection Classes: Shows how to make non-generic collection classes that can be used with the foreach statement.
  • COM Interop Part I: Shows how to use C# to interoperate with COM objects.
  • COM Interop Part II: Shows how to a use a C# server together with a C++ COM client.
  • Commandline: Demonstrates simple command-line processing and array indexing.
  • Condiational Methods: Demonstrates conditional methods, which provide a powerful mechanism by which calls to methods can be included or omitted depending on whether a symbol is defined.
  • Delegates: Shows how delegates are declared, mapped to static and instance methods, and combined into multicast delegates.
  • Events: Shows how to declare, invoke, and configure events in C#.
  • Explicit Interface: Demonstrates how to explicitly implement interface members and how to access those members from interface instances.
  • Generics: Shows how to make generic collection classes that can be used with the foreach statement.
  • Hello World: A Hello World application.
  • Indexers Part I: Shows how C# classes can declare indexers to provide array-like access to objects.
  • Indexers Part II: Shows how to implement a class that uses indexed properties. Indexed properties enable you to use a class that represents an array-like collection.
  • Libraries: Shows how to use compiler options to create a DLL from multiple source files; also, how to use the library in other programs
  • Named and Optional (C# 4.0): Demonstrates Named and Optional parameters, an alternative to method overloads
  • Nullable: Demonstrates value types, such as double and bool, that can be set to null
  • Office Sample (C# 4.0): Demonstrates how Dynamic and COM Interop make it easy to call Microsoft Office in C# 4.0
  • OLEDB: Demonstrates how to use a Microsoft Access database from C# by creating a dataset and adding tables to it.
  • Operator Overloading: Shows how user-defined classes can overload operators
  • Partial Types: Demonstrates how classes and structures can be defined in multiple C# source-code files
  • PInvoke: Shows how to call exported DLL functions from C#
  • Properties: Shows how properties are declared and used; also demonstrates abstract properties
  • Python Sample (C# 4.0): Learn how to call a Python script by using the Dynamic feature in C# 4.0
  • Security: Discusses .NET Framework security and shows how to modify security permissions in C# by using permission classes and permission attributes
  • Simple Variance (C# 4.0): See how Covariance and Contravariance are supported in generic interfaces and delegates
  • Structs: Shows how to use structs in C#.
  • Threading: Demonstrates various thread activities such as creating and executing a thread, synchronizing threads, interacting between threads, and using a thread pool
  • Unsafe: Shows how to use unmanaged code (code that uses pointers) in C#
  • User Conversions: Shows how to define conversions to and from user-defined types
  • Versioning: Demonstrates versioning in C# by using the override and new keywords
  • XML Documents: Shows how to document code by using XML
  • Yield: Demonstrates how to use the yield keyword to filter items in a collection

Was This Post Helpful? 0
  • +
  • -

#12 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Extracting File from the Resources.

Posted 21 August 2010 - 05:35 AM

Here is a BIG suggestion....learn to use IntelliSense. You know..that little window that pops up when you start typing? That IntelliSense. It will give you the methods/properties/classes that are available to you. If what you are typing isn't showing up in IntelliSense, then you have another problem.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1