المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : gif Image



C# Programming
04-11-2009, 05:30 PM
Hi,
I embedded some files in the assembly, html(text) images(gif, jpg, png).
What i want to do is extract all the files to a tmp directory.

I had SUCCESS in getting all the files to tmp directory. I open the text files..PERFECT. but images are not right, it says corrupt. How do I get the images extracted correctly from embedded resource and save it to disk.

Following is my piece of code.


private void button1_Click(object sender, EventArgs e)
{
Assembly _assembly;
Stream _imageStream;
StreamReader _StreamReader;

StreamWriter _StreamWriter;
string dirpath = Application.StartupPath + "\\help";
string[] resourceNames = this.GetType().Assembly.GetManifestResourceNames();
foreach (string resourceName in resourceNames)
{
//get resource if it is help
if (resourceName.Contains(".help"))
{
MessageBox.Show(resourceName);
try
{
if (!Directory.Exists(dirpath))
{
DirectoryInfo di = Directory.CreateDirectory(dirpath);
di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
di.CreateSubdirectory("images");
}
string filename = Application.StartupPath + "\\help\\";

//if image, it should save in image folder
if (resourceName.Contains(".images")) filename = filename + "images\\";
//get the filename and append it to the filename
string[] filenamearray = resourceName.Split('.');
int length = filenamearray.Length;
filename = filename + filenamearray[length - 2] + "." + filenamearray[length-1];

string read = null;

_assembly = Assembly.GetExecutingAssembly();
_StreamReader = new StreamReader(_assembly.GetManifestResourceStream(resourceName));
_StreamWriter = new StreamWriter(filename);

while ((read = _StreamReader.ReadLine()) != null)
{
_StreamWriter.WriteLine(read);
}
_StreamWriter.Close();
_StreamReader.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}


Thanks a lot for you precious time and knowledge,

Regards,
Karmendra