|
whatever code it takes to download a PDF, put it also in the loop, just after the code that creates it.
not sure to what you want to download, and whether download is the right word.
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.
|
|
|
|
|
If he is creating a pdf, surely he doesn't mean download as he is writing it to a location on his HD (wouldn't streamwriter or any other writer throw some sort of security exception for writing to a network share or anything else)?
Maybe he means open?
System.Diagnostics.Process.Start() ?
|
|
|
|
|
Some people use "download" to indicate a transfer to some smaller device (embedded, mobile, whatever), just like you and I "upload" things to a larger device (server, web site, ...).
In that view download/upload are unrelated to import/export, and you could create and download something.
That is how (I think) I understood his post.
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.
|
|
|
|
|
Could you be more specific?
What if the world was your spoon.
What if was in your power to bend it to your liking.
What if it could provide for you whatever you asked of it.
|
|
|
|
|
I'm still trying to get a block of code that does an https file download working. The vendor (swift.com) says that they took my code and got it working on their end no problem which leads me to believe that the something that is preventing me lives on my side of the request. We have a download scanner that pops up when I load the URL in my browser, so it's possible that I'm getting blocked there but I'm still working with the security team on that one. I'd appreciate it if someone could take a look at my code below and let me know if you see anything that's wrong/missing/poorly formed for an https request. This is being run from a .NET 2.0 console application if that makes any difference. I highlighted the line in the code where the 401 Unauthorized error occurs.
I added a few hard returns to the code to keep the page from going WAY WIDE. If you pull the code down from here and past it into VS you might have to remove them.
private bool DownloadFile()
{
private const string URL = "https://www2.swift.com/bicdownload/bicdownloader?
action=getfile&productline=bicdir&product=bicdb&content=full&format=txt&platform=win";
try
{
string bicFileTemp = string.Format("{0}\\BIC-{1}.txt",
ConfigurationManager.AppSettings["BICDLPath"], DateTime.Now.ToString("dd-MMM-yyyy"));
string line;
System.Net.NetworkCredential cred = new System.Net.NetworkCredential();
cred.UserName = "myUserName";
cred.Password = "myPassword";
WebRequest myReq = WebRequest.Create(URL);
myReq.Credentials = cred;
myReq.Proxy = WebProxy.GetDefaultProxy();
myReq.Proxy.Credentials = CredentialCache.DefaultCredentials;
* ERROR HERE * 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());
return true;
}
catch (Exception ex)
{
Utilities.ReportError("Error in BIC-DownloadFile: " + ex.Message, this, ex.StackTrace);
return false;
}
}
Mike Devenney
modified on Friday, May 29, 2009 11:35 AM
|
|
|
|
|
The only dodgy bit I can see is the proxy. Can you try connecting directly?
If your proxy is not forwarding your credentials correctly, you will get a 401.
I forget how, but there is a way to add your username and password to the URI. It's something like https://username:password@www.... Might be worth a try.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Thanks for the reply Nick. Tried removing the Proxy but I don't get off the network if I do. Maybe embedding the credentials in the URI will work. I'll give that a go and let you know how I make out.
Mike Devenney
|
|
|
|
|
You'll have to find a computer that isn't behind your proxy. Do you run a DMZ? Or a web server? You can always try from someone's home.
I just googled the URI encoding and I got it right
http://en.wikipedia.org/wiki/URI_scheme[^]
Please let us know how you get on.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
And the games continue. My username for the SWIFT site is my password, which includes the @ sign. I got an error back saying that
a port # is expected because a colon was found in the request. I assume this is happening because of the @ in my username. Would I escape the @ character?
Mike Devenney
|
|
|
|
|
Not sure about that.
Have you tried putting the uri in a web browser?
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Before I was getting an error about having a colon in the request with no port specified. Now, I get this error from IE in a dialog box entitled Address Bar.
Windows cannot find
'https://mdevenney@wilmingtontrust.com:Password@www2.swift.com/bicdownload/bicdownloader?action=getfile&productline=bicdir&product=bicdb&content=full&format=txt&platform=win'. Check spelling and try again.
Mike Devenney
|
|
|
|
|
I don't know how to escape an @ in your username. I just tried putting the uri without username:password into ie8 and a dialog popped up asking for credentials. Could you try this, enter your credentials and see if you get the file?
If you do, it means your account and local network are working, which would narrow the problem down to the credentials your proxy is passing when you use WebRequest.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
I'm able to get the file using the URI and entering the credentials into the dialog that pops up. Is there any way to see what the proxy is passing?
Mike Devenney
|
|
|
|
|
You could try setting myReq.PreAuthenticate = true; Might work...
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Sounds like your idea of the proxy server interfering is a winner. I'm talking over my head here but I'll do my best to explain what I just learned. I spoke with two of our architects who said that any https requests have to spoof a validated certificate because our infosec dept strips out the remote host's certificate and inserts one of their own. I have some sample code that one of them uses for a web service that makes https requests. Because it's a web service the code is slightly different but it's the same idea...
ServicePointManager.ServerCertificateValidationCallback
+= new RemoteCertificateValidationCallback(ValidateRemoteCertificate)
private static bool ValidateRemoteCertificate
(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
{
return true;
}
By "faking" the true value for the ValidateRemoteCertificate method the authentication succeeds and the connection will open successfully. I'm off to work this into my routine. If/when I get it working I'll post the "correct" code. Thanks for helping me work through this!
Mike Devenney
|
|
|
|
|
GAH
Thought that the certificate was going to be the silver bullet but I still get my now least favorite response: The server returned an error: (401) Unauthorized. I'm headed back to the drawing board. Not defeated yet, but getting there.
Mike Devenney
|
|
|
|
|
Hi guys
How can i Create buttons dinamyclly?
i want to add 20 buttons for example.
I tried to use an array and put all needed properties in a for loop but it is not working.
i think i forgot something
|
|
|
|
|
Show us what you have already then
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
for(int i=0;i<20;i++)
{
Button buttonName = new Button();
buttonName.property = property;
this.Controls.Add(buttonName);
}
Enjoy, add delegates for events!
|
|
|
|
|
thats exactly what i forgot
this.Controls.Add(buttonName);
thanks!
|
|
|
|
|
In the above example how would you modify the button's location in C#
for (int i = 0; i < 20; i++)
{
Button buttonName = new Button();
buttonName.Location.X = i * 20;
this.Controls.Add(buttonName);
}
When I try this I get an error message
Cannot modify the return value of 'System.Windows.Forms.Control.Location' because it is not a variable
I think I should have created an array of button pointers, but I can't remember how.
Thanks in advance
|
|
|
|
|
Just change
Douglas Kirk wrote: buttonName.Location.X = i * 20;
to
buttonName.Location = new Point(i * 20,whatever_you_want_as_y);
and you're done.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Hi,
if you know how to do things in Visual Designer (say position a button), then you can watch the code it generates (for a form myForm that would be in the InitializeComponents method inside file myForm.designer.cs).
So there is no magic involved, you can try and put similar code where ever you want, be it in the Form's constructor, load handler, a button click handler, you choose.
Apart from that, it helps to look up things in the documentation (use google to locate stuff) and to interpret compiler messages to the letter.
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.
|
|
|
|
|
I'm editing an existing library of user controls and I must admit, my experience is limited. These user controls are a combination of other user controls, mainly buttons and and panels. They where created to mimic the companies existing controls used in webapps for our desktop applications. Simple, and it works but they where initially designed for limited scalability.
So now the requirement emerges that each control should be resizable without altering the relative position of controls, some of which are transparent. I'm implementing this by, what appeared to be the easy task of reordering controls in the document outline and editing each controls dock and padding properties, which worked fine for a couple of controls.
Now I have the following outline: (control names reduced to simplicity to avoid confusion)
|---UserControl
|---Panel1
|---Panel2
|---Panel3
|---Button1
|---Button2
|---Button3
I dock Panel1 to DockStyle.Fill to the Parent UserControl to ensure that the control is resizable for obvious reasons, My problem is Panel2, which is overlayed on Panel1 by 6 pixels from the left and right respectively, I wish to keep this same fixed distance from the parent despite resizing, so I set dock to Fill and padding for left and right to 6 each, figuring this would work. It doesn't, which makes me feel I misunderstand the usage of Padding to begin with.
Any suggestions on where I went wrong and what would be the proper usage to enable this resizable implementation work as intended?
Sorry for weak explanation / poor ASCII art.
|
|
|
|
|
If you look into the anchor property instead of dock. that will do what you want and keep the 'indent'. Problem with the anchor is it may not work how you want it to if you have a lot of controls in the same control. i.e. 3 panels that need to have a 3rd of the form space each can not be handled with either dock nor anchor - that would need to be done manually on a resize event.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|