|
Here is way to write images to an XML file:
Image image = Image.FromFile(@"image file path");
MemoryStream memStream = new MemoryStream();
image.Save(memStream, image.RawFormat);
byte[] array = memStream.ToArray();
string imageString = Convert.ToBase64String(array);
Now all you have to do is to write this string to the XML file.
In order to read the image from the string, you can use this:
string imageString = "read the image string from XML file";
byte[] imageBytes = Convert.FromBase64String(imageString);
MemoryStream memStream = new MemoryStream(imageBytes);
Image image = Image.FromStream(memStream);
Although, it would be better if you store image files at a location and just the path in the XML files. In case you are dealing with large images, you would have a very bulky XML file."No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem
|
|
|
|
|
Hi Dinesh,
can i know how to insert an image in an xml file sice xml file consists of only tags can you please do send me the sample link if any to my mail so that i can make samples of it
|
|
|
|
|
He showedspoonfed you how to turn the image into an "xml-clean" string, surely you know how to insert a string into an xml file, otherwise how can you be using an xml file at all?
|
|
|
|
|
I already posted the code. What else are you looking for? "No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem
|
|
|
|
|
I'm creating a series of controls that I need to draw myself.
They are all derived from Control and each overrides OnPaint().
The main parent control paints itself fine. It maintains a list of the second-level controls and they paint fine too. Each of these second-level controls contain their own lists of third-level controls, that ideally will draw themselves too but at the moment, OnPaint(), does not get called for them.
Seems strange that the other two classes are able to paint and this last one is not.
|
|
|
|
|
Forgive my newbie question. I am trying to learn C#. I have utterly confused myself in trying to restart a server console. I do not have the server start on this yet but it locks up every time I restart and I am not real sure way. It shutsdown ok but then never makes the check if the process has exited. Can anyone give me a nudge in the right direction? Thanks
public void restartserver(string serverrs, string serverloc)
{
Process p = Process.GetCurrentProcess();
Process[] servername = Process.GetProcessesByName(serverrs);
IntPtr serverHandle = FindWindow(null, serverloc);
if (serverHandle == IntPtr.Zero)
{
if (serverrs == "arcemu-world")
{
btnWorldStatus.Text = "World Server is not running";
}
else
{
btnLogonStatus.Text = "Logon Server is not running";
}
}
else
{
SetForegroundWindow(serverHandle);
SendKeys.SendWait("Shutdown{ENTER}");
FreeConsole();
bool mytrue = true;
while (mytrue)
{
if (p.HasExited)
{
mytrue = false;
if (serverrs == "arcemu-world")
{
btnWorldStatus.Text = "Closing....";
}
else
{
btnLogonStatus.Text = "Closing....";
}
}
}
}
}
|
|
|
|
|
Maybe This[^] will help you..
|
|
|
|
|
Thanks for your help. After taking a look at the information provided I got it.
|
|
|
|
|
Is it spinning inside the while loop while (mytrue)? Also how did you verify the server has shutdown?
|
|
|
|
|
1. You are checking if your current process has exited instead of checking if the process you are killing has exited or not.
2. You are not using the Process array you have created (in the code block posted). So why even retrieve it?
Following code might help you out:
Process[] processList = Process.GetProcessesByName("proccessName");
MessageBox.Show("Killing processes...");
try {
foreach (Process process in processList) {
process.Kill();
process.WaitForExit();
}
MessageBox.Show("Processes killed successfully.");
}
catch (Exception exception){
MessageBox.Show("Could not kill on of the processes.");
}
You can also use the other overload of WaitForExit and provide a suitable time out. In case you use that, then, after the call to the method, check if the process has exited and display the appropriate method if process is still running."No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem
|
|
|
|
|
HELLO EVERYBODY,
I have a problem, I load a pdf in a webbrowser in Windows, in this event
string gcPthTMP = @"C:\TMP\";
string gcPthTrans = @"C:\TRANS\";
private void frmWebBrowser_Load(object sender, EventArgs e)
{
Uri uriPdf = new Uri(gcPthTMP + fileName);
this.webBrowser.Url = uriPdf;
}
This works fine, the problem is when I want to delete this file, i do:
private void frmWebBrowser_FormClosed(object sender, FormClosedEventArgs e)
{
this.webBrowser.Dispose();
this.Refresh();
System.Threading.Thread.Sleep(1000);
string fileName = this.txtUrl.Text.ToString().Trim();
this.Dispose(true);
if (System.IO.File.Exists(gcPthTMP + fileName))
{
System.IO.File.Delete(gcPthTMP + fileName);
}
}
this works fine in Vista, because delete the file without any problem, but the problem is in XP, this produce a error It says that the process is using by other process. Please help me, Ineed to solve this problem.
Thanks
|
|
|
|
|
why do you start a new thread?
why don't you reply to this[^]?
and why are you shouting the subject line?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Hello,
I trying puting a Thread
Thread tMosDocPdf = new Thread(new ThreadStart(DoShowPDF));
tMosDocPdf.Start();
when i load the file, but this dosen't works
After this in the event closed, i abort the Thread, but i obtain the same error, that I cant't dele this file because this is using for other process,
I think that the problem is with the plataform XP, because in Vista It woks fine
|
|
|
|
|
in addition to not responding to Luc's comments, you still havnt really made an attempt to find out whats locking the file on XP, have you ? (ie what proceses have the file) ..
until you do that, and we cant do it for you, I doubt anyone can suggest a solution
'g'
|
|
|
|
|
Garth J Lancaster wrote: until you do that, and we cant do it for you
True, and it funny how he thought of Luc's "forum thread" as a C# Thread
|
|
|
|
|
I'm not sure if it's possible but it would work if you can load it through a stream and close it before disposing the webbrowser object.
|
|
|
|
|
I already gave a tested solution on the older thread...
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Hi,
I am using DAAB with stored procedures. I stored procedure is called from multiple functions.
Please guide how I can handle optional parameters with DAAB ? a stored procedure has 2 parameter and values are being passed by functiona1. In function2 I needed to declare 3rd parameter in same stored procedure. I set its default value (so that I may have not to pass it from function1) but even than functions1 stop working and show error message that no of parameters are not same.
I am just selecting data in stored procedure and I have not coded any set statement (like set ansi on or set norowcount) in it.
Please guide me.
thanks
|
|
|
|
|
If you do something like this in method1
<br />
SqlCommand.Parameters.Add( [param1] )<br />
SqlCommand.Parameters.Add( [param2] )<br />
SqlCommand.Execute...<br />
Then this in method2
<br />
SqlCommand.Parameters.Add( [param1] )<br />
SqlCommand.Parameters.Add( [param2] )<br />
SqlCommand.Parameters.Add( [param3] )<br />
SqlCommand.Execute...<br />
as long as SqlCommand is the same object in both methods, then of course calling method1 after method2 will produce this exception, because you do have too many parameters. I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks for your kind attention.
I am not using command object. Rather I am passing parameters in directly in database object. e.g.
public int UpdateInvestmentObjectivesNExperience(CorporateAccount obj)
{
int result;
object objResult = db.ExecuteNonQuery("p_corporateaccount_InvestmentObjectivesNExperience", 2, obj .Id,
obj.SpecuativeGains, obj.HedgeAgainstInvestment, obj.InvestmentObjective,
obj.UndarstandNatureOfTCD, obj.UnderstandRiskOfTCD, obj.HaveExperienceOfTCD,
obj.NoOfMonthsExp, obj.TypesOfProductsDealtIn, obj.BrokersUsed, obj.WasAdviceReq,
obj.AvgTransationSize, obj.AvgNoOfTradesPerWeek);
result = Int32.Parse(objResult.ToString());
return result;
}
If I add a new parameter in stored procedure and set its default value by null or 1, than not only I will have to supply value for it in next functions where I am using it rather I will have to supply value for it in this method as well. (for the parameter that is last in stored procedure and has default value.)
Please guide.
thanks gain
|
|
|
|
|
If I understand what you are trying to accomplish then try this.
public int Foo(param1, param2)
{
return Bar(param1, param2, null);
}
public int Bar(param1, param2, param3)
{
return db.Execut(...);
} I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks a lot for your kind attention and sharing.
I m exectly doing this now but I here is problem what I asked. On declaring a new parameter I will have to pass value for it in all above functions where even it is not being used.
I was surprised can there be some why I may have not change the code again and again.
thanks
|
|
|
|
|
You want to be able to write one method and never change it again even when you change the stored procedure?
public SqlCommand CreateProc(string procName, ReadOnlyCollection<DbParameter> parameters)
{
SqlCommand cmd = new SqlCommand(procName, SqlConnection);
cmd.CommandType = CommandType.StoredProcedure;
if(parameters != null)
{
foreach(DbParameter param in parameters)
{
cmd.Parameters.Add(param);
}
}
return cmd;
}
I know the language. I've read a book. - _Madmatt
modified on Monday, February 15, 2010 11:40 AM
|
|
|
|
|
Thanks for it.
Can you please explain a little more how it will helpful ? how I can use it ?
thanks
|
|
|
|
|
I thought it was pretty self-explanatory. What don't you understand? I know the language. I've read a book. - _Madmatt
|
|
|
|