Welcome Guest.   Make a donation to an author on the site October 31, 2014, 07:59:52 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2011! Download 30+ custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1] 2 Next   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Check Gmail using C#  (Read 21468 times)
kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« on: September 30, 2010, 10:03:08 PM »

I've scoured the web for several days, looking for code allowing me to check my Gmail account programmatically in an application written in C#.  Found lots of examples (most pointing back to the OpenPop library), but no working examples -- and haven't been able to hack together my own working example either.

I have the same luck when I try to find actual working C# code to upload a file to a website directory using C#.  So any help in that regard would also be much appreciated.
Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

wraith808
Supporting Member
**
Posts: 6,445



"In my dreams, I always do it right."

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: September 30, 2010, 10:42:39 PM »

I uploaded a simple FTP class to snipplr that might help.  You can find it at http://snipplr.com/view/16451/simpleftp-class/.  Let me know if you have any questions.
Logged

Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,958



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #2 on: October 01, 2010, 02:31:19 AM »

If you use labels and filters in your GMail account you will need to use IMAP to access all of your mail. POP will only grab things that are labelled 'inbox'.
Logged

kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #3 on: October 01, 2010, 07:28:10 AM »

Thank you both for your help.

Wraith, can the snippet be downloaded without the line numbers?  And do you have a short snippet showing the class in use?  For example, say I want to download ...

ftp://mysite.com/myfile.jpg

to C:/localFile.jpg

username="myName"

password="myPass"

Could you snow me a snippet that will do that?  I know I must seem dense (probably AM), but it just helps.


Carol, thanks for the tip about POP; didn't know that.
« Last Edit: October 01, 2010, 07:30:28 AM by kyrathaba » Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

EĆ³in
Charter Member
***
Posts: 1,400


O'Callaghan

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #4 on: October 01, 2010, 07:28:53 AM »

Following on from Carol's suggestion to use IMAP, you should find the info and links in this StackOverflow question very helpful- Accessing Imap in C#?
Logged

Interviewer: Is there anything you don't like?
Bjarne Stroustrup: Marketing hype as a substitute for technical argument. Thoughtless adherence to dogma. Pride in ignorance.
wraith808
Supporting Member
**
Posts: 6,445



"In my dreams, I always do it right."

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #5 on: October 01, 2010, 11:21:04 AM »

If you click the plain text link, it will convert it to plain text.

As for a code sample:

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using UtilsLib;
  11.  
  12. namespace MyFTP
  13. {
  14.    public class Downloader
  15. {
  16. private bool DownloadFile()
  17. {
  18. var ftpMyFile = new UtilsLib.SimpleFTP
  19. {
  20.    LocalFilePath = "C:\",
  21.    LocalFileName = "localFile.jpg",
  22.    URI = "mysite.com",
  23.    UserId = "myName",
  24.    Password = "myPass",
  25.    RemoteFileName = "myfile.jpg",
  26.    UseBinaryMode = true
  27. };
  28.  
  29. bool ftpResult = ftpMyFile.InitiateTransfer(OnFTPProgress, OnFTPStart, OnFTPFinish);
  30. return ftpResult;
  31. }
  32.  
  33. public void OnFTPFinish(bool ftpSuccessful, string message)
  34. {
  35. if (!(ftpSuccessful))
  36. {
  37. // Do whatever you want if the ftp is unsuccessful
  38. }
  39. else
  40. {
  41. // Do whatever you want if the ftp is successful
  42. }
  43. }
  44.  
  45. public void OnFTPStart(string message)
  46. {
  47. // for reporting of progress - called when the FTP starts
  48. }
  49.  
  50. public void OnFTPProgress(int bytesTransferred, string message)
  51. {
  52. // do whatever updating of progress that you want to do
  53. }
  54. }
  55. }
Logged

kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #6 on: October 01, 2010, 01:08:37 PM »

Awesome, Wraith!  Thanks!!

I'll share my own cool discovery:


I run a roleplaying game on www.myth-weavers.com at http://www.myth-weavers.c.../forumdisplay.php?f=11199

I've been developing an application for my players that will allow them to create a new character and submit it to me, their Game Master, as an email attachment, for my perusal and approval.  In thinking ahead to the Game Master application I'll be creating at some point, one of the functions I want it to have is that it automatically checks my Gmail account when the application starts, to see if any players have emailed me any character files.

Well, I've experimented until I found a way to do this.

The following brief code snippet is simply proof of concept.  It uses the free ImapX DLL.  In my example below, I set a Subject Line to look for that signals my program I've found the right email (in this case "myflag").  Then, it looks through my Gmail emails until it finds such an email, and downloads the email itself as a *.eml file, and saves the first attachment to the same directory.

This snippet is very crude, but could be refined to download all attachments (if there are more than one).  I could build in error-checking to ensure there IS an attachment before trying to save it to file, etc.

[copy or print]
            ImapX.ImapClient client = new ImapX.ImapClient("imap.gmail.com", 993, true);
            bool result = client.Connection();
            if (result) {
                result = client.LogIn("myaddress@gmail.com", "myPassword");
                if (result) {
                    ImapX.FolderCollection folders = client.Folders;
                    foreach (ImapX.Message m in client.Folders["INBOX"].Messages)
            {
              m.Process();                   
                      if (m.Subject == "myflag") {
                          string path = Application.StartupPath + "\\email\\";
                          string filename = "myEmail";
                          m.SaveAsEmlToFile(path, filename);
                          m.Attachments[0].SaveFile(path);
                      }
            }
                }
            }
            else {
                MessageBox.Show("connection failed");
            }

Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #7 on: October 02, 2010, 07:56:40 AM »

Improved code-listing:

Snipplr code snippet

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1. /* Required for this example:
  2.              *
  3.              * a C# WinForms application
  4.              * add reference to ImapX.dll available here:
  5.              * http://hellowebapps.com/wp-content/uploads/2010/07/ImapX_1.2.3.126.zip
  6.              * http://dl.dropbox.com/u/12124382/ImapX.zip
  7.              * a button <button1>
  8.              * a textbox <textBox1>
  9.              *
  10.              * Notes: I used a very specific Subject line as my search criteria, but you need not do this.  You could
  11.              * just as easily have your code search through and download each and every email and/or every email's attachments.
  12.              */
  13.  
  14.  
  15.            ImapX.ImapClient client = new ImapX.ImapClient("imap.gmail.com", 993, true);
  16.            bool result = client.Connection();
  17.            if (result) {
  18.                result = client.LogIn("myself@gmail.com", "mypassword");
  19.                if (result) {
  20.                    textBox1.AppendText(Environment.NewLine + Environment.NewLine + "Log-on successful" +
  21.                        Environment.NewLine + Environment.NewLine);
  22.                    ImapX.FolderCollection folders = client.Folders;
  23.                    foreach (ImapX.Message m in client.Folders["INBOX"].Messages)
  24.                {
  25.                  m.Process();
  26.  
  27.                      if (m.Subject == "test email with 3 attachments (txt, png, wav)") {
  28.                          textBox1.AppendText(Environment.NewLine + Environment.NewLine + "Found email in question..." +
  29.                              Environment.NewLine + Environment.NewLine);
  30.                          string path = Application.StartupPath + "\\email\\";
  31.                          string filename = "TxtPngWav";
  32.                          //comment-out following line if you don't want to d/l the actual email
  33.                          m.SaveAsEmlToFile(path, filename);
  34.                          //use above line, and comment out the following if(){}, if you prefer to download the whole
  35.                          //email in .eml format
  36.                          if (m.Attachments.Count > 0) {
  37.                              for (int i = 0; i < m.Attachments.Count; i++) {
  38.                                  m.Attachments[i].SaveFile(path);
  39.                                  textBox1.AppendText("Saved attachment #" + (i + 1).ToString());
  40.                                  textBox1.AppendText(Environment.NewLine + Environment.NewLine);
  41.                              }
  42.                          }                          
  43.                      }
  44.                }
  45.                }
  46.            }
  47.            else {
  48.                textBox1.AppendText("connection failed");
  49.            }
« Last Edit: October 02, 2010, 10:20:58 AM by kyrathaba » Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

mouser
First Author
Administrator
*****
Posts: 33,611



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #8 on: October 02, 2010, 07:59:55 AM »

nice.
Logged
kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #9 on: October 11, 2010, 09:43:10 PM »

And since I've shown how to check Gmail using C# and Gmail's IMAP, the following snippet shows how to send an email programmatically, through your Gmail account, using C# and Gmail's SMTP.  Please note that, although the code doesn't require notification to the user that an email is about to be sent, you should always notify the end-user of your program, and give him/her the option of whether or not to send the email.  If you don't, their firewall or protective software may scare them when it pops up a message about your program attempting to send email.

Notes:

(1) your namespace's using section should include the following:
using System.Net.Mail;

(2) my example code places the email-sending code in a Button's Click() event-handler

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1.       private void button1_Click(object sender, EventArgs e) {
  2.            DialogResult dr = MessageBox.Show("Send email?", "Get Permission", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
  3.                MessageBoxDefaultButton.Button2);
  4.  
  5.            if (dr == DialogResult.Yes) {
  6.  
  7.                SmtpClient smtpClnt = new SmtpClient("smtp.gmail.com", 587);
  8.  
  9.                try {
  10.  
  11.                    MailMessage oMail = new MailMessage();
  12.                    oMail.To.Add(new MailAddress("recipient_email@wherever.com"));
  13.                    oMail.From = new MailAddress("yourAddy@gmail.com");
  14.                    oMail.IsBodyHtml = true;
  15.  
  16.                    oMail.Body = "your message body goes here";
  17.                    oMail.Subject = "your subject goes here";
  18.  
  19.                    smtpClnt.Timeout = 100000;
  20.  
  21.                    smtpClnt.EnableSsl = true;
  22.                    System.Net.NetworkCredential nc = new System.Net.NetworkCredential("yourAddy@gmail.com", "your_password");
  23.                    smtpClnt.Credentials = nc;
  24.  
  25.                    Attachment oAttached = new Attachment("C:\\yourimage.jpg");
  26.                    oMail.Attachments.Add(oAttached);
  27.  
  28.                    smtpClnt.SendCompleted += new SendCompletedEventHandler(MailDeliveryComplete);
  29.  
  30.                    smtpClnt.SendAsync(oMail, "sending");
  31.  
  32.                }
  33.                catch (Exception mailExc) {
  34.                    if (mailExc.ToString().IndexOf("could not be resolved") >= 0) {
  35.                        int line = mailExc.ToString().IndexOf("line");
  36.                        int leng = mailExc.ToString().Length;
  37.                        string sLin = mailExc.ToString().Substring(line, (leng - line));
  38.                        string s = "Either the developer's Gmail SMTP was unavailable, or else your computer is not currently ";
  39.                        s += "connected to the internet.  Error generated at source code " + sLin;
  40.                        MessageBox.Show(s, "Unable to send character file via email");
  41.                    }
  42.                    else {
  43.                        MessageBox.Show("Error:" + Environment.NewLine + Environment.NewLine +
  44.                            mailExc.Message + Environment.NewLine + Environment.NewLine + mailExc.ToString());
  45.                    }
  46.                }
  47.                finally {
  48.  
  49.                    //don't invoke smtpClnt.Dispose() here; if you do, the mail never sends
  50.                }          
  51.  
  52.  
  53.            }
  54.        }
  55.  
  56.  
  57.  
  58.        private void MailDeliveryComplete(object sender, System.ComponentModel.AsyncCompletedEventArgs e) {
  59.  
  60.            string myMessage = e.ToString();
  61.            string myCaption = string.Empty;
  62.  
  63.            if (e.Error != null) {
  64.                myCaption = "Error sending email";
  65.            }
  66.            else if (e.Cancelled) {
  67.                myCaption = "Sending of email cancelled.";
  68.            }
  69.            else {
  70.                myCaption = "Your email message was sent successfully to the Game Master.";
  71.            }
  72.  
  73.            MessageBox.Show(myMessage, myCaption);
  74.  
  75.        }
« Last Edit: October 11, 2010, 09:48:24 PM by kyrathaba » Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

mouser
First Author
Administrator
*****
Posts: 33,611



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #10 on: October 11, 2010, 09:44:02 PM »

cool  thumbs up
Logged
kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #11 on: October 11, 2010, 09:50:03 PM »

Made some modifications in the snippet above, for sake of clarity.  Users please note: it may not be a good idea to use a MessageBox to alert the user of your program to the success/failure of the email sending attempt (then again, that may be exactly what you want).
Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #12 on: October 12, 2010, 12:40:02 PM »

If anyone is reading these posts and knows the answer to the following questions, let me know:

How does one programmatically monitor and show the end-user, via a progress bar, the progress as a large email (say, a couple of large attachments) is sent?  The way Outlook Express and Outlook do.

How does one programmatically delete a Gmail message from the Inbox (by removing its "INBOX" label, for instance).
Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

wraith808
Supporting Member
**
Posts: 6,445



"In my dreams, I always do it right."

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #13 on: October 12, 2010, 01:17:31 PM »

If you look in your code at line 28, you have a delegate added for what to do when the process completes.  Hopefully, there is also a delegate for progress; you'd add your progress bar actions in that delegate.  You'll also need to check invokerequired on whatever UI elements that you are updating, as it's possible that it will be on a separate thread.

As for the delete, I'm not sure- you'd probably have to check the library that you're using to see how to do that.
Logged

kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #14 on: October 12, 2010, 05:32:51 PM »

Unfortunately, the library is offered "as-is"; no documentation whatsoever, so far as I've been able to find.
Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

wraith808
Supporting Member
**
Posts: 6,445



"In my dreams, I always do it right."

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #15 on: October 12, 2010, 07:13:56 PM »

Isn't it open source?  If not, you could take a look at http://www.codeproject.com/KB/IP/imaplibrary.aspx.  I haven't tried it, but the source is there.  Or http://xemail-net.sourceforge.net/.  Maybe they'll have support for callback delegates.
Logged

kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #16 on: October 14, 2010, 09:22:01 PM »

I'll check into it
Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #17 on: December 03, 2010, 01:16:55 PM »

Hmm, it seems that I cannot get a file to upload to my website, using C#.  Here's my code (note: the only substitutions made here are that I've substituted "my_username" for my actual website username, and "my_password" for my actual password to the website):

I keep getting a 404: not found error.

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1. private void button1_Click(object sender, EventArgs e) {
  2.            WebClient client = new WebClient();
  3.            client.Credentials = new System.Net.NetworkCredential("my_username", "my_password",
  4.                @"http://www.glensforkumc.com");
  5.            client.UploadFile("http://www.glensforkumc.com/non_church/myfile.txt", "localFile.txt");
  6.        }
Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

worstje
Honorary Member
**
Posts: 555



The Gent with the White Hat

View Profile Give some DonationCredits to this forum member
« Reply #18 on: December 03, 2010, 02:59:51 PM »

Well, HTTP does not support file uploads in the way FTP just lets you upload a file to a location.

There are forms you can submit that can contain a file upload, but that is not the same thing as that requires a script on the other side to interpret and do with it whatever needs doing. Likewise, unless you use HTTP authentication, that credential method probably wouldn't work as most sites tend to rely on a cookie-based solution

So, depending on your situation, you might have to change your approach to either ftp, or a more involved script-based solution.
Logged
Stoic Joker
Honorary Member
**
Posts: 5,346



View Profile WWW Give some DonationCredits to this forum member
« Reply #19 on: December 03, 2010, 03:35:58 PM »

does this help any?

http://www.codeproject.co...ields-cookies-and-he.aspx

I bing'ed it.
Logged
kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #20 on: December 03, 2010, 04:14:16 PM »

Tried the code shown in the screenshot, with the resultant error (note: I'm trying to upload file "UploadDownload.pdb" that resides in the application directory of my C# app.  I want to upload it to the following directory:

http://www.glensforkumc.com/non_church/

I expected an error about not supplying a username and password (which should be required), but I'm getting the following:

Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

Stoic Joker
Honorary Member
**
Posts: 5,346



View Profile WWW Give some DonationCredits to this forum member
« Reply #21 on: December 03, 2010, 05:23:17 PM »

Hm... I don't usually work in C# (yes that's a disclaimer) But in the code samples I saw online polking around, I got the impression that the filename needs to be added to the target url so it knows where to put it. Something like this:

Client.UploadFile("http://www.glensforkumc.com/non_church/"+FileName)

Also if IIS is configured to allow anonymous access, you're never gonna get asked for a password. Thy breaking the project into seperate chunks. (Temporarily) Allow anonymous write access to the target directory, set the NTFS permissions to allow it also, and then try uploading the file.

Also make sure you pick a small file to start/test with because IIS has default size/time limits that tend to bite.
Logged
kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #22 on: December 03, 2010, 06:44:46 PM »

Hmm, yeah, I can see why some of the examples would lead you to think that a concatenation is called for; however, there's no overload of the method that takes a single argument:

Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

wraith808
Supporting Member
**
Posts: 6,445



"In my dreams, I always do it right."

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #23 on: December 03, 2010, 09:42:43 PM »

I'd take a look at the comment provided by worstje.

If you really have to use http, then you can write the file to the request stream, or emulate a post as to a form.  I've not really done either of these (only using ftp), but a quick search came up with this topic.
Logged

kyrathaba
N.A.N.Y. Organizer
Honorary Member
**
Posts: 3,014



while(! dead_horse){beat}

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #24 on: December 04, 2010, 09:51:26 AM »

Thanks, guys.  Following up on your links and doing some reading, I've discovered it seems inordinately involved to accomplish what I'm wanting to do with http.  I'll keep researching this.  I have the following domain, which I've had for the past 18 months:

http://www.glensforkumc.com

It's a church website, but I pay for the space personally, and reserve the "non_church" subdirectory for my own use (hey, we've got 600 GB of storage, and after 18 months of use we've only used about 2 GB Wink)

So, I have the required username and password to access the website.  I'm able to use FileZilla easily to upload files.  I realize that the difference is that FileZilla is using FTP, not HTTP.

What I'm looking for is simple code (no more than a few lines) to upload a local file to a specified subdirectory on the website.  I'll continue reading from the posts you linked to, and thanks!
Logged

Win 7 Home Premium 64bit-SP1 AMD Athlon II X2 220 Socket AM3 (938) @ 2.1GHz 6GB RAM Firefox 26.0
_________________________________________________________________________________________

I'm fighting against patent trolls. Join me and tell your representative to support the #SHIELDAct: https://eff.org/r.b6JJ /via @EFF

My DC page: http://kyrathaba.dcmembers.com | My blog: http://williambryanmiller.com/ | Proofreading Service: http://bit.ly/1fQSqQP

Pages: [1] 2 Next   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.11s | Server load: 0.13 ]