|
What do you mean if syntax is incorrect? Can you give an example?
-----------------
Picazo
|
|
|
|
|
Hi,
I haven't tried this yet, however I expect new DirectoryInfo(path) would throw an exception when it doesn't like your path.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
thanks, at least some provblems are solved.
|
|
|
|
|
Hi all,
Sometime ago I wrote some automation tool to get content of some site.
Everything worked fine untill one day...
My C# code creted url string and made http hit. I used HttpRequest and Response.
Request looked like http://somesite.con/param1=a¶m2=b¶m3=c
Now, there was a change in the site and it always makes redirect to the url that looks like:
http://somesite.con/param1=a¶m2=b¶m3=c&rnd=AbCdEfG1.
With the fiddler I saw that actially web browser makes 2 hits:
1. The old one.
2. The new one.
Now the response of the first hit contains some JS code that generates this random code (AbCdEfG1), concatinates it to the main url and makes redirect.
As far as I understand I need to execute this JS from C#. It's may be done in the several ways and seems not too complex to do.
But then I need to or:
a. get back this random value from JS.
b. allow to JS to make redirection, but need to get back the response.
I prefer the b. because code that generates this random value always different (code generation or something).
The code of JS is something like that:
html>
<head>
<title></title>
</head>
<script type="text/javascript">
function redirect()
{
var redirectLoc = window.location.href;
if (redirectLoc.indexOf ('?')>-1) redirectLoc +="&"; else redirectLoc+="?";
redirectLoc = redirectLoc.replace (/rnd=[0-9a-zA-Z]+&/,"");
window.location = redirectLoc+'rnd='+f1();
}
</script>
<script type="text/javascript">
function sbbpWvum()
{
nCc = typeof "zCa";
return String.fromCharCode(nCc.charCodeAt(4)^37);
}
function f1()
{
return sbbpWvum();
}
Any one can help with this isue?
Thanks.
modified on Friday, August 14, 2009 10:04 AM
|
|
|
|
|
Still no ideas ?
|
|
|
|
|
What is best solution for logging app data when crashed.
Is it possible to log data into xml or other formats a unhandled expections, where the data woud specify file, line and possibly a dump
|
|
|
|
|
If you use Vista, then you can use its Application Recovery to recover from a crash. There's an article on CP for it here: Vista Application Crash Recovery in C#[^]
If you're going to save data, then I would make it as simple as possible. If you've got the Exception object, then the stack trace, exception type name and exception message would be a good start. You'd also want to get that for the InnerException, if it's not null. For the purposes of error logging, I'd just serialisation. It's still easily emailable, can be saved into XML format, and will have the data you need. And there's very little which can go wrong with it, so you're highly unlikely to get an exception, which would trigger the exception handler, which would raise an exception, which would trigger the exception handler ad infinitum.
Obviously if your application handles secure data, then you've got to save it in encrypted format. This can still use serialisation; you just need to save it to a CryptoStream instead of a FileStream
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
all,
I had an application that could access an mdb file via OleDb (Provider=Microsoft.Jet.OLEDB.4.0).
I received a new machine now, which is an x64 and it stopped working. It only works if I open up the solution and press F5 (doesn't matter if it is release or debug). So I did some searching and changed the provider (Provider=Microsoft.ACE.OLEDB.12.0) which works the same as above and also used a target x86 platform to build the application (I read x64 wasn't supported). Same behaviour. double clicking the exe fails to open the database, pressing F5 works without problems.
Here's the error:
Error: Could not connect to database: Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\vmalisse\Desktop\astrid_v21_result.mdb;User Id=admin;Password=;.<br />
error: The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception.
Can anyone point me to the problem? I'm not quite sure what exactly is wrong.
thanks.
|
|
|
|
|
According to MSDN forums your app might have configuration problem.
Life is a stage and we are all actors!
|
|
|
|
|
Thank you very much for the reply, apparently as you said, there is a configuration problem. I needed to ADD an App.config to my application. It's empty, but that did the trick.
|
|
|
|
|
Hi,
my app logs correctly while code is beeing executed within my method DoIt . But it doesn't log in the Process.OutputDataReceived 's EventHandler even if p_OutputDataReceived is called.
Is there anything I need to look at while using Process ?
private void DoIt(string arguments)
{
_log.Fatal("TEST");
Process p = new Process();
p.StartInfo.FileName = @"D:\vssTOOLS\NetJobs\UpdateDealArchiveInstrSeq\UpdateCaller\bin\Debug\UpdateDealArchiveInstrSeq.exe";
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Caller)).Location);
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments = arguments;
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit();
do
{
System.Threading.Thread.Sleep(100);
} while (!p.HasExited);
if (p.ExitCode != 0)
{
for (int i = 0; i < procOut.ToString().Length; i += 2000)
_log.Info(procOut.ToString().Length > i + 2000 ? procOut.ToString().Substring(i, 2000) : procOut.ToString().Substring(i));
for (int i = 0; i < procErr.ToString().Length; i += 2000)
_log.Error(procErr.ToString().Length > i + 2000 ? procErr.ToString().Substring(i, 2000) : procErr.ToString().Substring(i));
throw new ApplicationException("Es ist ein Fehler aufgetreten: " + procErr.ToString());
}
}
StringBuilder procOut = new StringBuilder();
StringBuilder procErr = new StringBuilder();
void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
procErr.AppendLine(e.Data);
_log.Error(e.Data);
}
void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
procOut.AppendLine(e.Data);
_log.Info(e.Data);
}
|
|
|
|
|
Hi,
I am using a procedure which selects some rows and handles a output parameter.
I am executing this procedure using SqlDataReader.
Problem Is ,
If Connection is kept open after ExecuteReader(), Sql Reader is working fine and able to do data binding. But, output parameter is returing null value.
If Connection is closed, I am able to get the correct output parameter value. But, SqlDataReader is not working.
Any Ideas to make both working regardless of connection status.
Thanks,
Nagaraj
|
|
|
|
|
You can't. You only get the ouput parameter back when you close the connection. Its always been that way.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Thanks Bob,
My code is fetching the records for GridView Binding (for the selected PageIndex) and total results in single call to database.
I am returing SqlReader from DAC to BusinessLayer and to Code file from there.
Is there any better way to achive this?
Thanks again
Nagaraj
|
|
|
|
|
DataReader needs open connection.
Better you use DataSet, DataAdapter.
|
|
|
|
|
You could use a dataset and fill that, I think you would then get your output parameter straight away - not 100% sure though, I haven't tried it. Alternatively, return 2 recordsets and use a dataadaptor to fill a dataset, you then should get what would have been the output param in its own table.
Hope some of this helps
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Ashfield wrote: think you would then get your output parameter straight away
Unfortunately not - you have to iterate over the lot before you get the output parameter back. This has caused me grief a few times.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: Unfortunately not - you have to iterate over the lot before you get the output parameter back
Ought to have guessed that really.
I never tried it, I generally don't bother with output parameters simply because you can't get them when you really want them, usually first! If I need something like that I often return 2 record sets, the 1st with what would be the output parameter and the 2nd with the real data - probably not ideal, but it works for me
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
I have this button that I want disabled from a check box on a separate form. Its an options window and one option is to disable a certain button but the button is on the previous from. How can i disable the button from the form? I cant just start typing because it does not know the button exists. due to it being on another form.
Y*Live Long And Prosper*Y
|
|
|
|
|
Raise an event in the form with the checkbox that the form with the button subscribes to.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
You might want to delete the repost you made above this one before you get flamed for it! I think the CP servers had a bit of a fit a few minutes ago, so probably when you thought it hadn't submitted - it actually had.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
yeah sorry lol I thought it didn't go through
Y*Live Long And Prosper*Y
|
|
|
|
|
You could do it using events or delegates or custom WM messages
|
|
|
|
|
Can someone please be more specific? Im new to programming.
Y*Live Long And Prosper*Y
|
|
|
|
|
Working Example:
using System;
using System.Windows.Forms;
public partial class FormButton : Form
{
public FormButton()
{
InitializeComponent();
}
private void FormButton_Load(object sender, EventArgs e)
{
FormCheckBox formCheckBox = new FormCheckBox();
formCheckBox.CheckStateChanged += formCheckBox_CheckStateChanged;
formCheckBox.Show();
}
void formCheckBox_CheckStateChanged(object sender, CheckStateEventArgs e)
{
button1.Enabled = e.IsChecked;
}
}
using System;
using System.Windows.Forms;
public partial class FormCheckBox : Form
{
public event EventHandler<CheckStateEventArgs> CheckStateChanged;
public FormCheckBox()
{
InitializeComponent();
}
private void checkBox1_CheckStateChanged(object sender, EventArgs e)
{
OnCheckStateChanged(new CheckStateEventArgs(checkBox1.Checked));
}
protected virtual void OnCheckStateChanged(CheckStateEventArgs e)
{
EventHandler<CheckStateEventArgs> eh = CheckStateChanged;
if (eh != null)
eh(this, e);
}
}
public class CheckStateEventArgs : EventArgs
{
public CheckStateEventArgs(bool isChecked)
{
IsChecked = isChecked;
}
public bool IsChecked
{
get;
private set;
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|