Click here to Skip to main content
15,913,298 members
Home / Discussions / C#
   

C#

 
QuestionCan some body tell me why it behaves like this Pin
netJP12L31-Oct-08 11:14
netJP12L31-Oct-08 11:14 
QuestionActivating last textbox in DataGridView on form active Pin
AndrusM31-Oct-08 10:37
AndrusM31-Oct-08 10:37 
QuestionCancel the transformMatrix in Graphics Pin
baranils31-Oct-08 9:58
baranils31-Oct-08 9:58 
QuestionWindow as seperate thread. Pin
vaseeem31-Oct-08 9:52
vaseeem31-Oct-08 9:52 
GeneralRe: Window as seperate thread. Pin
Luc Pattyn31-Oct-08 10:40
sitebuilderLuc Pattyn31-Oct-08 10:40 
QuestionNewbie Property Binding Question Pin
Chris Klepeis31-Oct-08 9:50
Chris Klepeis31-Oct-08 9:50 
QuestionLooking for C# example to create Image Metadata app [modified] Pin
DrGerm31-Oct-08 9:35
DrGerm31-Oct-08 9:35 
QuestionFtpWebRequest Upload question Pin
KaptinKrunch31-Oct-08 8:38
KaptinKrunch31-Oct-08 8:38 
Im using the FtpWebRequest object to upload a file to an FTP server. The problem is that if a directory that is part of the remote path does not exist, it fails. Otherwise the file is upload with out error with the code below.

I'd almost like to assume that since the request method is UploadFile, that it would create directories as needed. But I must be wrong. So is there be a way to accommodate dynamic creation of the directories?

The Error Message
[System.Net.WebException] = {"The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."}

Here's some code to review if you wish.

The UriBuilder
UriBuilder uB = new UriBuilder();
uB.Scheme = Uri.UriSchemeFtp;
uB.Host = ConfigurationManager.AppSettings["FTPRemoteHost"].ToString();
uB.UserName = ConfigurationManager.AppSettings["FTPRemoteUser"].ToString();
uB.Password = ConfigurationManager.AppSettings["FTPRemotePass"].ToString();
FileInfo uFInfo = new FileInfo(localpdf);
uB.Path = remotepath + uFInfo.Name;


The value of the UriBuider Uri property
{ftp://username:password@myftpserver/existingDirectory/missingDirectory/mydocument.pdf}


The function I'm working with
        public bool UploadFile(Uri serverUri, string localFile)
        {
            if (serverUri.Scheme != Uri.UriSchemeFtp)
                return false;

            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.UseBinary = true;
            
            if (File.Exists(localFile) == false)
                return false;

            StreamReader sourceStream = new StreamReader(localFile);
            byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
            sourceStream.Close();

            if (fileContents.Length <= 0)
                return false;

            request.ContentLength = fileContents.Length;


            try
            {
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return false;
            }

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
#if(DEBUG)
            WriteEvent(response.StatusDescription, EventLogEntryType.Information);
#endif
            response.Close();
            request.Close();
            return true;
        }


Just because we can; does not mean we should.

Questionhow to retreive correct control.visible property of a hidden control in c# Pin
Dino2Dino31-Oct-08 8:32
Dino2Dino31-Oct-08 8:32 
AnswerRe: how to retreive correct control.visible property of a hidden control in c# Pin
EliottA31-Oct-08 9:50
EliottA31-Oct-08 9:50 
AnswerRe: how to retreive correct control.visible property of a hidden control in c# Pin
Giorgi Dalakishvili31-Oct-08 11:45
mentorGiorgi Dalakishvili31-Oct-08 11:45 
GeneralRe: how to retreive correct control.visible property of a hidden control in c# Pin
Luc Pattyn31-Oct-08 12:21
sitebuilderLuc Pattyn31-Oct-08 12:21 
QuestionRe: how to retreive correct control.visible property of a hidden control in c# Pin
nelsonpaixao31-Oct-08 13:49
nelsonpaixao31-Oct-08 13:49 
AnswerRe: how to retreive correct control.visible property of a hidden control in c# Pin
Dave Kreskowiak1-Nov-08 5:20
mveDave Kreskowiak1-Nov-08 5:20 
QuestionList<int> in wpf designer</int> [modified] Pin
vincentgr31-Oct-08 8:02
vincentgr31-Oct-08 8:02 
AnswerRe: List in wpf designer Pin
Pedram Behroozi31-Oct-08 8:16
Pedram Behroozi31-Oct-08 8:16 
GeneralRe: List in wpf designer Pin
vincentgr31-Oct-08 8:33
vincentgr31-Oct-08 8:33 
GeneralRe: List in wpf designer Pin
Pedram Behroozi31-Oct-08 8:41
Pedram Behroozi31-Oct-08 8:41 
QuestionSNMP Trap or Packet Listner Program --Socket Question. Please advice Pin
jobin00700731-Oct-08 7:23
jobin00700731-Oct-08 7:23 
AnswerRe: SNMP Trap or Packet Listner Program --Socket Question. Please advice Pin
jobin0070075-Nov-08 15:54
jobin0070075-Nov-08 15:54 
QuestionTabControl question Pin
aalex67531-Oct-08 6:29
aalex67531-Oct-08 6:29 
AnswerRe: TabControl question Pin
Pedram Behroozi31-Oct-08 7:33
Pedram Behroozi31-Oct-08 7:33 
GeneralRe: TabControl question Pin
aalex67531-Oct-08 7:37
aalex67531-Oct-08 7:37 
GeneralRe: TabControl question Pin
Pedram Behroozi31-Oct-08 7:56
Pedram Behroozi31-Oct-08 7:56 
QuestionHow to get a list of open files? Pin
Dirk.Bock31-Oct-08 5:40
Dirk.Bock31-Oct-08 5:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.