|
Well, this is what asynchronicity is all about. If you were looking for something like callback functions, I don't know any BeginLoad() methods. Yet this should work the same.
Regards
|
|
|
|
|
Thank you for your response.
Orkun GEDiK
SAP R/3 BASIS and Development Consultant
ASTRON
|
|
|
|
|
Hello,
I'm using MS Access as database back-end for my C# application and I have an OLE Object field in my MS Access Database and I want to extract the content (say JPG image) to the users' desktop.
I'm using OleDB and C#.NET 2.0.
How can I do that?
Thanks.
|
|
|
|
|
Hello
O'm not sure if this would work or not, but read it as binary in a stream, and build an image object from that stream.
Regards
|
|
|
|
|
Thanks Nader it almost worked but I'm no getting a text file extracted well... the first line is:
$ ےےےےPackage Package Package ²{ Sa.txt C:\DOCUME~1\Owner.Joe\Desktop\SA.txt $ C:\DOCUME~1\Owner.Joe\Desktop\SA.txt S{ ...
Then the content of my file begins!
The same for the last line:
METAFILEPICT " »ْےےî "E s 2 ' ûُے گ Tahoma è
vـٍ ¸¤َwء¤َw 0ُw‘"f
- ےےے . ! Sa.txt! û ¼ ²"System ‘"f
& ٹ ےےےےhَ - L
What's worng?
Thanks.
|
|
|
|
|
Textfile?? You didn't mention text? I thought you said that you are reading an image from the database, so you should read it as binary stream then on the fly call Image.FromStream() method. Why did you create a text file for the image?
What you got is binary, and it won't be displayed properly by any text editor -eg. notepad-. If I'm getting you wrong or missing something, please clarify.
Regards
|
|
|
|
|
I thought it's the same thing so I said image just to make it simple
Ok so now I have an access db and I'm inserting an html document into an OLE field by right clicking and choosing insert object...
How can I - by code - extract the exact html file and save it to the user desktop?
|
|
|
|
|
Well, please don't be offended, I was just wondering. To some extent yes, it could be almost the same.
For the Html document you are storing -though I'd prefer to store it in the Db as text. This would be much easier-, the Html text itself won't be changed, but you wil find some binary OLE Metadata at the begining of the doument. You just got to ignore it in your Stream, and begin reading from the first Html tag -eg. <html>, or <body>, etc..-. That should do it, but then you have to treat it like text and not binary like storing it in a string and saving it to html file. Also the images of the html page won't be saved in the Db, and when you extract the file and save it to "something.html" you will only get the html and no pictures -except of course if they are online pictures, and you were connected-.
I hope I was close enough this time.
-- modified at 22:29 Sunday 15th October, 2006
Oh! I almost forgot. About the metadata at the end, just ignore whatever is after the </html> tag.
BTW: How do you extract the Oleobject from you Db in C# code?
Regards
|
|
|
|
|
I'm trying to parse html that resides locally by using the HtmlDocument class
and unfortunately you can only get an instance of an HtmlDocument through the
WebBrowser control.
Some of the html files I want to parse are quite large so I want to get the
HtmlDocument in a separate thread. But for some reason, whenever I move the
code to navigate the WebBrowser to a separate thread the DocumentCompleted
event is never fired. When I step through I can see that some of it is
loading but not all. Here is some code:
-----------
...<br />
Thread worker = new Thread(new ParameterizedThreadStart(LoadHtml));<br />
worker.SetApartmentState(ApartmentState.STA);<br />
worker.Start(files);<br />
...<br />
<br />
private void LoadHtml(object obj)<br />
{<br />
foreach(FileInfo fileinfo in (FileInfo[])obj)<br />
{<br />
HtmlParser parser = new HtmlParser(fileinfo);<br />
m_listHtmlParsers.Add(parser);<br />
}<br />
}<br />
<br />
public class HtmlParser<br />
{<br />
public HtmlParser(FileInfo fileinfo)<br />
{<br />
m_wbHtmlParser.DocumentCompleted +=<br />
new WebBrowserDocumentCompletedEventHandler(ParseHtml);<br />
m_wbHtmlParser.Navigate(m_fiChapterFile.FullName);<br />
}<br />
<br />
private void ParseHtml(object sender, <br />
ebBrowserDocumentCompletedEventArgs e)<br />
{<br />
}<br />
}<br />
------------------
If I take this out of the thread, the DocuementCompleted event get's fired
and everything works. I think what is happening is that the thread is being
exited before the document is completely loaded. But I'm not sure how to
make sure all the HtmlParsers have fired the DocumentCompleted event before
the thread ends.
Any help would be greatly appreciated.
|
|
|
|
|
If you need to parse HTML docs on background threads, you'll need to create the HTML control on that thread, then navigate using that same thread. Chances are navigation is getting screwed up because you created the control on one thread, then used it from another thread, which is a no-no.
|
|
|
|
|
Judah Himango wrote: If you need to parse HTML docs on background threads, you'll need to create the HTML control on that thread, then navigate using that same thread. Chances are navigation is getting screwed up because you created the control on one thread, then used it from another thread, which is a no-no.
I am creating the WebBrowser control inside of the HtmlParser object which is created in the background thread (or at least I think that's what's happening, I could have my threading code messed up). The WebBrowser control is a public property of the HtmlParser object.
|
|
|
|
|
Ok, a couple things I'd check: verify the HtmlParser is created on the same thread you're doing the parsing/navigating on. Also, if a background thread is indeed creating the HtmlParser, verify that thread's apartment state is STAThread.
|
|
|
|
|
Judah Himango wrote: Ok, a couple things I'd check: verify the HtmlParser is created on the same thread you're doing the parsing/navigating on. Also, if a background thread is indeed creating the HtmlParser, verify that thread's apartment state is STAThread.
<br />
Thread worker = new Thread(new ParameterizedThreadStart(LoadHtml));<br />
worker.SetApartmentState(ApartmentState.STA);<br />
worker.Start(files);<br />
...<br />
<br />
private void LoadHtml(object obj)<br />
{<br />
foreach(FileInfo fileinfo in (FileInfo[])obj)<br />
{<br />
HtmlParser parser = new HtmlParser(fileinfo);<br />
m_listHtmlParsers.Add(parser);<br />
}<br />
}<br />
<br />
I think this is doing both of your suggestions? Any other ideas?
|
|
|
|
|
IIRC, the WebBrowser control needs to be visible in order to have it's events fired. Try adding the HTML control to a form, make it visible, then try navigating. I recall some bug or something with that where it has to be visible before the Navigated et al events get fired.
|
|
|
|
|
Judah Himango wrote: IIRC, the WebBrowser control needs to be visible in order to have it's events fired. Try adding the HTML control to a form, make it visible, then try navigating. I recall some bug or something with that where it has to be visible before the Navigated et al events get fired.
I'll give that a try, but the thing is, it works not being visible or in a form if it's in the main thread.
|
|
|
|
|
jbrower1 wrote: I'll give that a try, but the thing is, it works not being visible or in a form if it's in the main thread.
That doesn't work either... The same thing happens
|
|
|
|
|
Where does the parsing occur there? Upon construction? Or do you need to .Navigate or something?
|
|
|
|
|
I have a sample code for client server application : But could not able to send the request. Can anybody help me out to correct it?
This is the server code:
class MoneyServer
{
ArrayList talk = new ArrayList();
public MoneyServer()
{
talk.Add("A penny saved is too small, make it a buck");
talk.Add("Keep your wooden nickel. It will be worth something someday");
talk.Add("It's your dime, but u r a better if dialing 10-10-XXX.");
}
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
MoneyServer mSvr =new MoneyServer();
ASCIIEncoding ASCII = new ASCIIEncoding();
Byte[] inStream = new Byte[256];
Byte[] outStream = new byte[256];
Random rnd;
string reqString="";
int index;
string choice = "Q";
TcpListener tcpl = new TcpListener(2010);
tcpl.Start();
Console.WriteLine("Server is running...");
choice = Console.ReadLine();
Console.WriteLine();
do
{
try
{
choice = Console.ReadLine();
Console.WriteLine();
Socket sock = tcpl.AcceptSocket();
int count = sock.Receive(inStream,inStream.Length,0);
reqString = ASCII.GetString(inStream,0,inStream.Length);
Console.WriteLine("reqString = " + reqString);
rnd = new Random();
index = rnd.Next(mSvr.talk.Count);
//outStream = ASCII.GetBytes((string)mSvr.talk[index]);
outStream = ASCII.GetBytes(choice);
sock.Send(outStream, outStream.Length, 0);
}
catch(Exception ex)
{
Console.WriteLine("Generic exception message : {0}",ex.Message);
}
}while(reqString != "bye");
tcpl.Stop();
}
}
This is the client code:
class EnterpreneurialClient
{
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
ASCIIEncoding ASCII = new ASCIIEncoding();
Byte[] inStream = new Byte[256];
Byte[] outStream = new Byte[256];
string freeAdvice;
string choice = "Q";
do
{
try
{
Console.WriteLine("\nMoney Line\n");
Console.WriteLine("1 - Get Advice");
Console.WriteLine("Q - Quite");
Console.WriteLine("\nPlease Choose: ");
choice = Console.ReadLine();
Console.WriteLine();
TcpClient myClient = new TcpClient("localhost", 2010);
Stream myStream = myClient.GetStream();
outStream = ASCII.GetBytes("What is the secreat of making money?");
if(choice == "1")
{
//send request to server
myStream.Write(outStream,0,outStream.Length);
//clean garbage chars from byte array
for(int i=0; i
|
|
|
|
|
Hi,
Ive been playing with the culturalInfo example provided in MSDN, and although I understand it, I dont understand what need there is for it.
If I have the following code:
TextBox1.Text = DateTime.Now.ToString("D");
I still get the correct date format, whether my Windows Regional Settings are set to English or Hungarian.
So why do I need the CulturalInfo class?
Regards
Mark
|
|
|
|
|
Whenever a value is formatted or parsed in a way that can be culturally dependent, a CultureInfo or a FormatInfo object is used. Even if you don't specify one, one is used. Every time, without exception.
For an example, this statement:
TextBox1.Text = DateTime.Now.ToString("D");
is equivalent to:
TextBox1.Text = DateTime.Now.ToString("D", CultureInfo.CurrentCulture);
Sometimes you want the format to use the current culture of the user, but sometimes you want a specific format that is independent of the culture. For that you can specify a custom format, create a specific CultureInfo or FormatInfo object, or use CultureInfo.InvariantCulture.
---
b { font-weight: normal; }
|
|
|
|
|
Here is a concrete example:
We had an application that was crashing on one device but worked fine with all the others.
The problem was coming from the culture and the parsing of a string. All the devices were in english excepted the one that kept crashing who was a French Pocket PC french. When we did something like Double.Parse("2.00") it would crash on the french device because the decimal separator in that culture is a comma and not a dot...
|
|
|
|
|
Hi Monkey,
so what was the answer to this? How did you fix the statement Double.Parse("2.00") to be multicultural?
|
|
|
|
|
There is two solution to that particular problem:
-generate number according to the culture info (myDouble.ToString() does that). In that case the number is generated with the current culture and can be parsed with Double.Parse() because it's the same culture (the current culture)
- Double.Parse is surcharged, it has a version with a second parameter which specify how to parse it. I don't have visual studio right now so I can't tell what it is but you can look it up.
That makes ou feel very dumb when you find such bug : what I'm not even able to do such a basic thing as parsing number!?!
|
|
|
|
|
how can i exit event handler..and dont execute code in this event handler when some condition occurs
|
|
|
|
|
Use the return statement
--------------------------------------------------------
My portfolio & development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|