0
這是一個上傳工具。我正在嘗試重命名文件名,如果它已存在於文件夾中。 該計劃是在文件名後添加一個數字。例如,如果文件名是Hello.doc,它將被保存爲Hello2.doc。如何在某個地方將字符串值插入/替換爲另一個字符串值?
問題是,文件名&文件類型總是不一樣。它可以是Goodbye.pdf/capture.png。我不知道如何在正確的位置插入數字。
if (System.IO.File.Exists(savepath))
{
int counter = 2;
while (System.IO.File.Exists(savepath))
{
string newFileName = fileName + counter;
tempFileName = newFileName.Insert/replace //Not sure what to do here
savepath += tempFileName;
counter++;
}
FileUpload.SaveAs(savepath);
lblUpload.Text = "A file with the same name already exists." + " Your file was saved as " + tempFileName;
}
有人知道嗎?謝謝!
它有幫助!謝謝! – 002432SAM