我寫了這段代碼用於設置文件名之前保存到我的電腦:爲什麼我只得到「的.xlsx」,而不是完整的連接字符串
string name_file = System.IO.Path.GetFileName(openFileDialog1.FileName).Split('.')[0]
+ blYear.SelectedValue == null ? "2010" : blYear.SelectedValue
+ ".xlsx";
我跟蹤代碼,並查看結果:
System.IO.Path.GetFileName(openFileDialog1.FileName).Split('.')[0] "PSIQ DIGITEL" string
blYear.SelectedValue null object
name_file ".xlsx" string
我做錯了什麼?爲什麼name_file
失去了原始值?同樣,在這個相同的問題中,我如何刪除最終file_name之間的空格,比如在例子「PSIQ DIGITEL」中應該是「PSIQ-DIGITEL」。
編輯
如果我刪除了這部分+ blYear.SelectedValue == null ? "2010" : blYear.SelectedValue
然後將文件名拿着值精細,有什麼不對?
什麼是'blYear'? – 2013-05-06 20:13:08
是一個組合框組件 – Reynier 2013-05-06 20:13:54
您應該使用'Path.Combine'來構建您的路徑。 'Path.Combine(part1,part2,part3,...)' – 2013-05-06 20:14:37