首页 > 解决方案 > 我收到一条错误消息,显示“不支持给定路径的格式”。尝试将音频文件上传到共享点时

问题描述

我可以使用下面的代码行上传其他文件类型以共享点。但是,当我尝试上传 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);
                }
        }

标签: c#asp.netsharepointfile-upload

解决方案


我怀疑我下面路径中的反斜杠是个问题

考虑对路径使用逐字运算符 (@)来表示它包含\应忽略的转义序列字符(符号)。

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\";

推荐阅读