|
Well, we have some software of ours downloading files from apache and i think you are making it way to difficult:
System.Net.NetworkCredential cred = new System.Net.NetworkCredential();
cred.UserName = "Your Username";
cred.Password = "Your Password";
System.Net.WebRequest req = new System.Net.WebRequest();
req.Credentials = cred;
Do Or Don't, there is no "try catch ex as exception end try"
|
|
|
|
|
thanks for that Noctris... worked for me
|
|
|
|
|
Thanks for the input to all who answered. We are in business. I think I had some extra credential passing going on and it must have been confusing the poor webserver.
Mike Devenney
|
|
|
|
|
Ok... turns out I was wrong. We are, in fact, not in business. I ran the code and didn't get any error so I assumed that all was well, but I wasn't getting to the line inhe code where the response was requested. When I removed the breakpoint and re-ran the code the 401 error was still happening on the line where I do:
WebResponse wr = myReq.GetResponse();
Anyone have any experience with the Automated SWIFT download that can see something in the code below that could be causing it to fail? I've spoken with their support team but they don't offer support on automation, all they could do is verify that my username and password were correct and that I was authorized (ironic, no?) to download the file.
System.Net.NetworkCredential cred = new System.Net.NetworkCredential();
cred.UserName = "mySWIFTUsername";
cred.Password = "mwSWIFTPassword";
WebRequest myReq = WebRequest.Create(URL);
myReq.Credentials = cred;
myReq.Proxy = WebProxy.GetDefaultProxy();
myReq.Proxy.Credentials = CredentialCache.DefaultCredentials;
WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader sr = new StreamReader(receiveStream, Encoding.UTF8);
StringBuilder bicFile = new StringBuilder();
do
{
line = sr.ReadLine();
bicFile.Append(line);
} while (line != null);
File.WriteAllText(bicFileTemp, bicFile.ToString());
Mike Devenney
|
|
|
|
|
I have a number of PictureBox controls that show a Street Stop Light. Each Picturebox control is controled by two radio buttons for a total of 8 picturebox control and 16 radio buttons. One for Run (turns the Stop Light Green) One for Stop (turns the light red). I am storing the name of the PictureBox control in the tag of it respective radio buttons. Can I take this string and use it to reference the Picturebox control and change the image?
Here is me code:
private void OnCheckedChange(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
if (rb.Checked && rb.Text.Contains("Run"))
{
OnLoadPictureImage(rb.Tag.ToString(), radioButton1.Checked);
}
else
{
OnLoadPictureImage(rb.Tag.ToString(), radioButton1.Checked);
}
}
private void OnLoadPictureImage(String picBox, Boolean ObjectStatus)
{
try
{
PictureBox pb = new PictureBox();
pb = (PictureBox)this.Controls[picBox];
if (ObjectStatus)
{
Stream s = File.Open("../images/traffic-light-green.jpg", FileMode.Open);
Image temp = Image.FromStream(s);
s.Close();
pb.Image = temp;
}
else
{
Stream s = File.Open("../images/traffic-light-red.jpg", FileMode.Open);
Image temp = Image.FromStream(s);
s.Close();
pb.Image = temp;
}
}
catch (Exception err)
{
MessageBox.Show("Error finding image: " + err.Message);
}
}
Is this not possible?
Thanks
Tom
Tom Wright
tawright915@gmail.com
|
|
|
|
|
why not just store a reference to the PictureBox in the Tag ?
[edit]
I may be making assumptions based on the limited scope of the code snippet, but shouldn't this
OnLoadPictureImage(rb.Tag.ToString(), radioButton1.Checked); instead read
OnLoadPictureImage(rb.Tag.ToString(), rb.Checked);
Why create a new PictureBox inside of OnLoadPictureImage here:
PictureBox pb = new PictureBox(); pb is immediately overwritten to another PictureBox so wouldn't it be better to set it to null and not waste the time or resources creating the throw-away object?
Last modified: 16mins after originally posted --
|
|
|
|
|
I did it that way because when I reference the PictureBox.image property I received and error that the object had not been instantiated.
Either way it's still null...almost like it cannot find it.
Oh...and I did have it like this:
OnLoadPictureImage(rb.Tag.ToString(), rb.Checked);
Just doing some debugging when I thought I'd post this to the forum and I forgot to set it back like I had it.
Thanks for the help.
Tom
Tom Wright
tawright915@gmail.com
|
|
|
|
|
The exact error was:
Object reference not set to an instance of an object.
T
Tom Wright
tawright915@gmail.com
|
|
|
|
|
where?
and in response to your original question,
pb = (PictureBox)this.Controls[picBox]; should work fine just fine as long as this.Controls[picBox] actually is a PictureBox . Doing a safe cast (this.Controls[picBox] as PictureBox ) and then checking for null would be a safer way to do it.
|
|
|
|
|
pb.Image = temp; <----- Here....when I try and set the image.
Tom Wright
tawright915@gmail.com
|
|
|
|
|
and pb is what's null? a safe cast (the as operator) and null check would be better than C-style cast and no null check, and as long as the object names are stored correctly in the Tag s then it should work.
|
|
|
|
|
modification to my previous statement:
in order for this to work:
pb = (PictureBox)this.Controls[picBox]; the picture box needs to be parented by the main form. If it exists on a child panel or a tab control or something like that then it won't exist in the main forms control collection. You'll have to recursively search the this.Control objects to find it.
Like I said before, why not just store the picture box itself in the tag of the radio button? Then you'd have
PictureBox pb = rb.Tag as PictureBox; and you'd be done.
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
{
for (int x = 0; x < this.Controls.Count; ++x)
{
for (int y = 0; y < this.Controls[x].Controls.Count; ++y)
{
if (this.Controls[x].Controls[y].GetType() == typeof(RadioButton))
{
RadioButton _rdbtn = (RadioButton)this.Controls[x].Controls[y];
_rdbtn.CheckedChanged += new EventHandler(_rdbtn_CheckedChanged);
}
}
}
}
void _rdbtn_CheckedChanged(object sender, EventArgs e)
{
for (int x = 0; x < this.Controls.Count; ++x)
{
for (int y = 0; y < this.Controls[x].Controls.Count; ++y)
{
if (this.Controls[x].Controls[y].GetType() == typeof(RadioButton))
{
RadioButton _rdbtn = (RadioButton)this.Controls[x].Controls[y];
if (_rdbtn.Checked == true)
{
for (int z = 0; z < this.Controls[x].Controls.Count; ++z)
{
if (this.Controls[x].Controls[z].GetType() == typeof(PictureBox))
{
PictureBox _pic = (PictureBox)this.Controls[x].Controls[z];
if (_pic.Tag == "Hi")
{
}
}
}
}
}
}
}
}
Take note...
if (rb.Checked && rb.Text.Contains("Run"))
{
OnLoadPictureImage(rb.Tag.ToString(), radioButton1.Checked);
}
else
{
OnLoadPictureImage(rb.Tag.ToString(), radioButton1.Checked);
}
will always execute irrelevant true or false.
i assume one is 'Unchecked'
This code should help only if you have the radio / image / etc. on panels.
remove the 2nd layer of loops if you not using panels...
Regards,
X
Yeee
modified on Tuesday, May 19, 2009 5:17 PM
|
|
|
|
|
I see. I did not know that I had to iterate through all of the controls. Currently the Radio buttons are in group fields. I have 6 sets of Run/Stop radiobuttons on my form in 6 group fields. I ran into a problem where they were not in group fields and then only one radiobutton was allowed to be selected from the rest.
Thanks for the help.
Tom
Tom Wright
tawright915@gmail.com
|
|
|
|
|
Hey guys, I've been googling this but with no luck
Here's what I need:
Lets say I've got a piece of plain text in a TextBox or RichTextBox, using a user specified regular expression, I need to find and copy(move to a second text box) everything that matches the said expression.
I hope that makes sense, I've got no real experience with regex so if you could point me to an article that would be great
Thanks
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Harvey Saayman wrote: so if you could point me to an article that would be great
Here you go[^]
|
|
|
|
|
|
Hello Fellow Coders;
Has anyone run across a convertor from the frequency of light to windows colors?
tia
rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Rafone wrote: Has anyone run across a convertor from the frequency of light to windows colors?
I never had until you asked the question, then i did this[^]
|
|
|
|
|
Hi Everyone,
I have a combobox that i need to populate with a datasource from my database. Because i want to make this autocomplete AND have the possibility to enter new things, i have done the following:
Private void LoadAuthors()
{
cmbAuthors.DataSource = Dataset;
cmbAuthors.DisplayMember = "Name";
cmbAuthors.ValueMember = "Id";
cmdAuthors.AutoCompleteCustomSource = AutoCompleteStringCollectionIMadeFromTheDataSet;
cmbAuthors.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
cmbAuthors.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
And all is well in Autocomplete land and datasource land.. however...
to find out if they entered a new name ( and i need to pop up a form to complete extra info), i have a handler for the "leave" event on the combobox:
private void cmbAuthors_Leave(object sender, EventArgs e)
{
if (cmbAuthors.SelectedValue != null)
{
MessageBox.Show("We know the dude...");
}
else
{
MessageBox.Show("Who's that ? better make a new one !");
}
}
now the problem is:
When you leave the combobox, the selectedvalue always is null, i get the "who's that" message, and when i click ok to that THEN the selectedindex event fires on the combobox (and thus only getting the required data to make this check)
Is there any way to make sure the selectedindex event is fired first or manually fire the autocomplete so it will complete BEFORE, it actually fires the leave event ?
Any other intelligent solution i could not think of or have not found on google codeproject is welcome too obviously
Do Or Don't, there is no "try catch ex as exception end try"
|
|
|
|
|
what about trying to replace
if (cmbAuthors.SelectedValue != null)
with
if(cmbAuthors.Items.Contains(cmbAuthors.Text))
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hmm.. unfortunately, it does not even recognize that
Strange thing is, if i look at what cmbAuthors.text contains, it is the text i want..
but it does not work. so that got me thinking and i tryed:
cmbAuthors.selectedtext = cmbauthors.text;
But.. helas.. it only uses the actual typed text so for example "mad" if you are looking for madonna :s
I am thinking that autocomplete uses the same event (leave) to do it's autocomplete magic..
When i change the handler to the "onSelectedValueChanged", it does work .. however, that event get's fired multiple times on Runtime (so when binding the datasource for example)... and does not fire when the value you type in is unknown in the dataset/autocomplete
The problem is that i really have to do the check when leaving the combo ...
Do Or Don't, there is no "try catch ex as exception end try"
|
|
|
|
|
For the people that want to know.
Apparently the Leave event is fired before autocomplete can do it's magic however, Putting the handler on the LostFocus event solves the issue. It's just not visibile in the VS2005 UI...
Solved
Do Or Don't, there is no "try catch ex as exception end try"
|
|
|
|
|
I have a toolstrip and added a combobox, i wish to populate that combo box with a list of fonts that will change the font in the textbox or richtextbox.
I have searched everywhere and only found one example but it's code didn't seem to work. I have tried myself but since this is all for learning.
Im using visual c# express.
Any help will be great thanks,
Malcom
Malcom
|
|
|
|
|
If you're looking to get the list of all fonts on the system, then use something like this:
System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
foreach(FontFamily family in families)
{
if(family.IsStyleAvailable(FontStyle.Regular))
{
Font font = new Font(family, 12, FontStyle.Regular);
}
}
That gets every font style and creates a Font object from it. From there it's simple enough to add the Font name to a combo box, and hook the SelectionChanged event to create a font from its name and set the textbox's Font property
|
|
|
|