|
Well if that's the case I tried renaming the folder name once the file is selected from the OpenDialog and i clicked on OK button. right. If i were to rename MYMAINFOLDER at
if (filename != "")
{---------------------------->even here doesn't let me to rename
Open(filename);
}
I have spent 2 hours and this thing making me to pull out my hairs. only couple left
|
|
|
|
|
Hi,
you must be doing something special you didn't mention since normally renaming a folder works just fine. Here is test code that works as expected for me:
using (OpenFileDialog d=new OpenFileDialog()) {
if (d.ShowDialog()==DialogResult.OK) {
string f=d.FileName;
log("f="+f);
string f2=f+"a";
File.Move(f, f2);
log("File rename OK");
string dir=Path.GetDirectoryName(f2);
log("dir="+dir);
string dir2=dir+"a";
Directory.Move(dir, dir2);
log("Folder renamed to "+dir2);
}
}
I do have some remarks when looking at your code;
1.
your if(openDialog != null) {openDialog = null;} isn't very useful; first of all, if you want it to be null, just write openDialog = null; . However if openDialog doesn't interest you any more, once your using block is closed, keep the declaration inside the using (as I did).
2.
Calling Dispose() on the subject of a using block is not looking good. The using block is there to take care of it.
3.
Don't call GC.Collect(), the way it works automatically will do a better job if you don't interfere with it.
Now the problem you are having may be caused by something you did not tell us; here are two likely causes:
1.
you did open and not close one of the files inside the path you are trying to rename; e.g. maybe you do a myPictureBox.Image=Image.FromFile(aFileInsideTheChosenFolder);
2.
you did create, write and close a new file inside the folder; although you closed it, some other process may be busy reading the file (an anti-virus scanner, an automatic indexing program, whatever). Try inserting a Thread.Sleep(3000) before you attempt to rename.
Hope this helps.
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.
|
|
|
|
|
|
|
d'oh!!! I can't believe I was actually sent an MSDN link. Not quite as bad as getting a "letmegooglethatforyou", but still ...I looked on the MSDN, but apparently didn't dig deep enough.
Actually, I think this isn't going to be a problem, after all. The mainframe database doesn't do any manipulation to the file coming in to it, so data gets stored as a binary stream in whatever encoding variant it was received in. Therefore, if it was originally encoded in ASCII before it was sent to the mainframe, when it will be retrieved, it will be thrown back in ASCII encoded binary. The program that creates the "bmp" or "3ds" or "mb" or "doc" or "rtf" or whatever would be responsible for encoding/decoding the binary stream that it created.
"I need build Skynet. Plz send code"
|
|
|
|
|
Alaric_ wrote: Not quite as bad as getting a "letmegooglethatforyou"
Sorry, I didn't intentionally snub you.
LetMeMakeThatUpToYou[^]
|
|
|
|
|
Hi,
1.
I am not following you. A binary file is a binary file, there is no ASCII and no EBCDIC involved. If the blob is truly binary, just get it in the normal way and use it.
2.
If your binary data is converted to a string (maybe using base64 encoding), then such string would be represented using some encoding, such as ASCII or EBCDIC; decoding a Unicode base64 is supported by .NET; decoding an EBCDIC base64 string would need explicit code, but could be made to run at the same speed as the normal Unicode (or ASCII) base64 decoding.
3.
Some data formats (JPEG is one of them) include a couple of characters; a JPEG file often starts with the letters JFIF. I do not know they always are in ASCII, I do know they are 8-bit. Check on an IBM system, if they start with ASCII "JFIF" then point 1 applies. If they start with EBCDIC "JFIF" them you need a smart converter, i.e. some code that knows which bytes are actually characters and knows how to translate them.
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.
|
|
|
|
|
|
As Luc said, if the data in your BLOB is, for example, a jpg file then it's binary data, and you don't need to convert it in any way.
On the other hand, if the BLOB contains a text file, and the text file is in EBCDIC, then you must convert it in order to be able to use it.
So, if I understand correctly your issue, you would need conversion only for a specific kind of content (pure text), and you must bypass conversion for all other "binary" data.
Note that passing binary data (like the content of a jpg file) to some EBCDIC to ASCII conversion routine will alter it and it won't be usable anymore!
The only other option I can think of is you are using some kind of encoding from binary data to EBCDIC, something similar to uuencoding[^], so you encode your binary data to EBCDIC and then store it in the BLOB. This wouldn't make much sense, but if that's how it works then you simply must decode it, and there's no way to avoid it.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
I've been working on automating a file download from the swift.com website. I don't know if this makes a difference but the site uses the Apache webserver. The documentation from SWIFT stresses that they're using the Apache HTTP Client Library, but their sample code is in Java, so that might be why. I assumed that a web request is a web request, regardless of the library you use to create it, but here I am asking for help, so maybe my assumption is incorrect. I've included a portion of the code I wrote to download the file.
...
WebRequest myReq = WebRequest.Create(URL);
string username = "me@mydomain.com";
string password = "myPassword";
string usernamePassword = username + ":" + password;
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(URL), "Basic", new NetworkCredential(username, password, "swift.com"));
myReq.Credentials = mycache;
myReq.PreAuthenticate = true;
myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));
myReq.Proxy = WebProxy.GetDefaultProxy();
myReq.Proxy.Credentials = CredentialCache.DefaultCredentials;
<-- Error occurs on the next line: The remote server returned an error: (401) Unauthorized -->
WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader sr = new StreamReader(receiveStream, Encoding.UTF8);
StringBuilder bicFile = new StringBuilder();
...
Anyone care to shed some light on this for me? I've logged into the site using the credentials so I know I have them right.
Mike Devenney
|
|
|
|
|
Mike Devenney wrote: myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));
I'm not sure you should be doing that since you are using WebRequest.Credentials. At least in the case I used it I did NOT add the Header. Of course my target was an IIS Server.
Also suspicious of
Mike Devenney wrote: myReq.PreAuthenticate = true;
Try it without those.
|
|
|
|
|
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
|
|
|
|