Other Software > Developer's Corner
Check Gmail using C#
kyrathaba:
Figured it out: I wasn't adding a filename and extension to the end of the filename I tried to build. DUH and DOUBLE-DUH!
kyrathaba:
@fodder: Thanks for being willing to take time and try to help. Turns out there isn't a problem, except me being inattentive.
If you can programmatically create a subdirectory, you can write a file there, as you'd expect.
f0dder:
Turns out there isn't a problem, except me being inattentive.-kyrathaba (December 26, 2010, 02:59 PM)
--- End quote ---
Bugs happen ^_^
If you can programmatically create a subdirectory, you can write a file there, as you'd expect.-kyrathaba (December 26, 2010, 02:59 PM)
--- End quote ---
Well, it's definitely what you'd expect - I was guessing that perhaps the IMAP library was running with more paranoid security settings or something. I should really find the time to read properly about .NET security.
kyrathaba:
I have the following functioning code to upload programmatically via FTP in C#:
--- Code: C# ---public void UploadFile(string FullPathFilename) { string filename = Path.GetFileName(FullPathFilename); try { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(_remoteHost + filename); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential(_remoteUser, _remotePass); StreamReader sourceStream = new StreamReader(FullPathFilename); byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); request.ContentLength = fileContents.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); response.Close(); requestStream.Close(); sourceStream.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Upload error"); } finally { }
Now for the problem. When I use this method in the following button click event, it does upload the file to the desired directory of my website, but then my UI hangs. I have to kill the program from within the IDE.
--- Code: C# ---private void btnUploadTxtFile_Click(object sender, EventArgs e) { string username = "my_username"; string password = "my_password"; string host = "ftp://glensforkumc.com"; try { clsFTPclient client = new clsFTPclient(host + "/httpdocs/non_church/", username, password); client.UploadFile(Path.GetDirectoryName(Application.ExecutablePath) + "\\myTextFile.txt"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Upload problem"); } }
Doesn't hang when using a similar method to download a file. Any idea why my UI is freezing up after a successful upload?
f0dder:
Have you tried tracing the UploadFile method in the VS debugger to see if there's any particular line of code that causes a hang?
It's not a good idea doing stuff like this from your UI thread, anyway... you should either schedule the task on a background worker thread, or (better) use Async I/O. I'll refrain from saying anything about having non-ui code in a btnWhatever_Click handler :)
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version