首页 > 解决方案 > 仅在文件扩展名之前获取一个句点

问题描述

我正在尝试制作一个小程序来从数据库中读取 URL 并将它们附加到 SAP B1 Deliveries。

示例源 URL: http://xxxx/xx/xxx/xxx/xxx/x/xxxx.pdf

代码:

oAttDelv.Lines.SourcePath = Path.GetDirectoryName(row.AttachURL);
oAttDelv.Lines.FileName = Path.GetFileNameWithoutExtension(row.AttachURL);
oAttDelv.Lines.FileExtension = Path.GetExtension(row.AttachURL);                    
int iErr = oAttDelv.Add();

int AttEntry = 0;

int temp_int = lErrorCode;
string temp_string = sErrorMsg;
oCompany.GetLastError(out temp_int, out temp_string);

temp_string 中显示的错误如图所示。如何解决 pdf 之前的两个句点并只得到一个句点?

错误:

temp_int = -5002
temp_string = "Source file does not exist  , 'http:\\*****************\\jspui\\bitstream\\123456789\\2444\\1\\500393..pdf'"

标签: c#url

解决方案


尝试这个:

var temp_string = @"Source file does not exist , 'http:\*****************\jspui\bitstream\123456789\2444\1\500393..pdf'";
var file_name = temp_string.Substring(temp_string.LastIndexOf(@"\") + 1).Replace("..", ".");

推荐阅读