我写了这段代码用于设置文件名之前保存到我的电脑:为什么我只得到“的.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