c# - 我收到一条错误消息,显示“不支持给定路径的格式”。尝试将音频文件上传到共享点时
问题描述
我可以使用下面的代码行上传其他文件类型以共享点。但是,当我尝试上传 uadio 文件时,在尝试创建目录并将文件保存在 SharePoint 上的行中出现错误,显示为“不支持给定路径的格式”。该行读取System.IO.Directory.CreateDirectory(pathString);
我怀疑我下面路径中的反斜杠是个问题
小路
public static string CMSdocs1drive = "\\\\myserver.sharepoint.com@SSL\\DavWWWRoot\\personal\\myname_myorganisation_org_com\\";
上传并保存到 SharePoint 的代码
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload_Section55_6.HasFile)
{
if (ddlDocument.SelectedIndex == 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + "Upload status: Please select the document type." + "');", true);
}
else
{
try
{
if (FileUpload_Section55_6.PostedFile.ContentLength < 2014572800)
{
{
if (ddlFilingType.SelectedIndex != 0)
{
if (!String.IsNullOrEmpty(lblCaseID0.Text) && ddlDocument.SelectedValue.ToString() == "203")
pathString = CMSProperties.CMSdocs1drive + "\\" + lblCaseID0.Text + "\\" + ddlFilingType.SelectedItem.Text + "\\" + ".Mp3";
}
if (!Directory.Exists(pathString))
{
System.IO.Directory.CreateDirectory(pathString);
// System.IO.Directory.Move(pathString);
}
if (pathString != controller.CheckIfFilePathExist(pathString))
{
controller.UploadFile(pathString, lblCaseID.Text);
}
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + "Upload status: The file is to big!" + "');", true);
}
ddlDocument.SelectedIndex = 0;
}
catch (Exception ex)
{
ex.Message.ToString();
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + "Upload status: The file could not be uploaded. The following error occured:" + "');" + ex, true);
Console.WriteLine();
}
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + "Upload status: Please select file " + "');", true);
}
}
解决方案
我怀疑我下面路径中的反斜杠是个问题
考虑对路径使用逐字运算符 (@)来表示它包含\
应忽略的转义序列字符(符号)。
public static string CMSdocs1drive = "\\\\myserver.sharepoint.com@SSL\\DavWWWRoot\\personal\\myname_myorganisation_org_com\\";
使用逐字运算符,您可以避免使用额外的转义序列字符,例如:
public static string CMSdocs1drive = @"\\myserver.sharepoint.com@SSL\DavWWWRoot\personal\myname_myorganisation_org_com\";
推荐阅读
- google-sheets - Google 表格中的异常查询
- python - 将系列中的最后一个值投影到 Python 中的未来单元格
- python - 如何解决“No module named 'frontend'”错误消息?
- ruby - 如何使用机械化单击(显然)无表单按钮/链接以在网页上“显示更多”
- java - 我试图在一个对象中分配一个变量数组,但不知道如何
- elasticsearch - 搜索多个添加的“search_data”
- node.js - 如果条件无法正常工作,因为我将变量的值设为未定义
- multithreading - 使用 serde_json::from_str 反序列化为带有 &'static 字符串的结构存在生命周期错误
- makefile - 如何在使用 Make 时改进 $(call $(eval $(call))) 范例?
- powerbi - DAX - 返回发布日期之前的最新日期