views:

193

answers:

0

Hi,

I am using the following code to delete a file from out Ftp server:

    private FtpWebRequest CreateFtpRequest(string requestUri, string method)

    {

        if (requestUri == null)

        {

            throw new ArgumentNullException("requestUri");

        }



        FtpWebRequest ftpWebRequest = null;



        try

        {

            ftpWebRequest = FtpWebRequest.Create(requestUri) as FtpWebRequest;

        }

        catch (UriFormatException e)

        {

            throw new InvalidOperationException("Uri '" + requestUri + "' is invalid", e);

        }

        catch (SecurityException e)

        {

            throw new InvalidOperationException("Uri'" + requestUri + "' is not available", e);

        }



        ftpWebRequest.KeepAlive = false;

        ftpWebRequest.UsePassive = false;

        ftpWebRequest.Method = method;

        ftpWebRequest.Credentials = new NetworkCredential("", "");



        return ftpWebRequest;

    }



    private void DeleteFtpFile(string fileName)

    {

        FtpWebRequest ftpWebRequest = CreateFtpRequest(fileName, WebRequestMethods.Ftp.DeleteFile);

        if (ftpWebRequest != null)

        {

            try

            {

                using (WebResponse response = ftpWebRequest.GetResponse())

                {

                    using (Stream streamReader = response.GetResponseStream())

                    {

                    }

                }

            }

            catch (WebException) { }

        }

    }

If the filename (TEST.ppv) does not contain a # character then I can successfully delete the file.

If the filename (TEST#1.ppv) does contain a # character then I get a web exception when trying to delete the file saying that the file does not exist. If I look at the logging on our server it looks the file trying to be removed is TEST.ppv i.e. the # and everything after it has been removed from the filename. I have no idea where this is happening.

Has anyone got an ideas on what might be going wrong?

Thanks

Ian