2015-01-10 31 views
1

我现在对代码非常困惑。我有一个CarPhoto对象,并在该对象是一个PhotoList列表。在该列表中是指向位于我的FTP服务器上的照片的链接。为什么我的URI不被支持? FileInfo Argumentexception

当我尝试删除该文件,我得到这个消息:

类型“System.ArgumentException”未处理的异常出现在mscorlib.dll

其他信息:URI格式不被支持。

下面的代码:

private void delete_Button_Click_1(object sender, EventArgs e) 
{ 
    DialogResult result = MessageBox.Show("Wilt u deze foto echt verwijderen?", "Foto verwijderen", MessageBoxButtons.YesNo); 
    if (result == DialogResult.Yes) 
    { 
     int index = imageLinkList.SelectedIndex; 
     CarPhoto photo = car.PhotoList[index]; 
     FileInfo fi = new FileInfo(photo.Photolink); //The exception gets thrown here.The link is: http://pqrojectqars.herobo.com/Images/Fiat/Punto/Wit/40.jpg 
     string extension = fi.Extension; 
    } 
} 

有人能帮助我吗?

+2

'FileInfo'描述了一个位于本地机器或UNC上的文件。它无法描述位于FTP服务器上的远程文件。 –

回答

0

感谢球员,但我已经找到了解决方案。你们给我的FTP答案已经在代码中,我只能找到文件的扩展名。它解决了。

0

您将需要使用FTP库连接到FTP服务器以删除该文件。

FileInfo不知道FTP。

0

FileInfo将只能用于本地文件或文件坐在UNC:

MSDN

指定的路径也可以指一个相对路径或通用 命名约定(UNC)在服务器和共享名路径

什么你可以要做的就是执行FtpWebRequest执行文件删除:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri); 
request.Method = WebRequestMethods.Ftp.DeleteFile; 

using (FtpWebResponse response = (FtpWebResponse) request.GetResponse()) 
{ 
    Console.WriteLine("Delete status: {0}",response.StatusDescription); 
}