Try Dim fbd As FolderBrowserDialog = New FolderBrowserDialog() If fbd.ShowDialog() = DialogResult.OK Then Dim path As String = fbd.SelectedPath() Dim fileNameList As ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles(path) For Each row As DataGridViewRow In DataGridView1.Rows Dim fileID As String = row.Cells(7).Value.ToString Dim plmID As String = row.Cells(8).Value.ToString Dim rowFileName As String = plmID & ".pdf" Dim filePath As String = "" '标准滤芯的上传路径 If plmID.StartsWith("504") Then filePath = "标准滤芯图纸" Else filePath = "产品资料/" & row.Cells(0).Value.ToString & "/工艺上传文件" End If For i = 0 To fileNameList.Count - 1 Dim fileName As String = My.Computer.FileSystem.GetName(fileNameList(i)) If rowFileName.Equals(fileName) Then Dim ftpFileName = "" '标准滤芯下的图纸使用PLM编码命名 If plmID.StartsWith("504") Then plmID = plmID.Replace("#", "$") ftpFileName = plmID & ".pdf" Else If fileID.Equals("0") Then ftpFileName = plmID & ".pdf" Else ftpFileName = fileID & ".pdf" End If End If '上传文件 FH.FtpUploadFile(path & "\" & fileName, filePath, ftpFileName) row.Cells(6).Value = "是" Exit For End If Next Next MsgBox("图纸上传成功!") End If Catch ex As Exception MsgBox("图纸上传失败!") End Try(翻译为C#)
时间: 2024-04-22 17:24:05 浏览: 14
以下是将给定的VB.NET代码翻译为C#的版本:
```csharp
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Windows.Forms;
public class MyClass
{
public void MyMethod()
{
try
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
string path = fbd.SelectedPath;
ReadOnlyCollection<string> fileNameList = Microsoft.VisualBasic.FileIO.FileSystem.GetFiles(path);
foreach (DataGridViewRow row in DataGridView1.Rows)
{
string fileID = row.Cells[7].Value.ToString();
string plmID = row.Cells[8].Value.ToString();
string rowFileName = plmID + ".pdf";
string filePath = "";
// 标准滤芯的上传路径
if (plmID.StartsWith("504"))
{
filePath = "标准滤芯图纸";
}
else
{
filePath = "产品资料/" + row.Cells[0].Value.ToString() + "/工艺上传文件";
}
for (int i = 0; i < fileNameList.Count; i++)
{
string fileName = Path.GetFileName(fileNameList[i]);
if (rowFileName.Equals(fileName))
{
string ftpFileName = "";
// 标准滤芯下的图纸使用PLM编码命名
if (plmID.StartsWith("504"))
{
plmID = plmID.Replace("#", "$");
ftpFileName = plmID + ".pdf";
}
else
{
if (fileID.Equals("0"))
{
ftpFileName = plmID + ".pdf";
}
else
{
ftpFileName = fileID + ".pdf";
}
}
// 上传文件
FH.FtpUploadFile(path + "\\" + fileName, filePath, ftpFileName);
row.Cells[6].Value = "是";
break;
}
}
}
MessageBox.Show("图纸上传成功!");
}
}
catch (Exception ex)
{
MessageBox.Show("图纸上传失败!");
}
}
}
```
请注意,翻译后的代码可能需要根据您的具体情况进行调整和优化。