简体   繁体   中英

uri formats are not supported for Ip address in C#

In my Web.Config file I have add my IP address in file path. when i try to access all files of that folder then it gives an error uri format not supported. but if i give local file path then it works fine.

string pathdata = Utility.GetConfigValue("DevSubmittedStateTaxForms");
string uploadPath = Utility.GetConfigValue("DevUploadFiles");

DirectoryInfo d = new DirectoryInfo(pathdata);
                FileInfo[] Files = d.GetFiles("*.pdf"); 

                var status = new List<Object>();
                int i = 1;
                foreach (FileInfo filename in Files)
                {
                    status.Add(new {ID = i, Name = filename.Name, URL = pathdata + filename.Name + ".pdf" });
                    i++;
                }
using System;
using System.IO;

namespace Test
{
    public class Program
    {
        static void Main(string[] args)
        {
            string pathdata = @"\\192.168.1.27\Temp\";

            var d = new DirectoryInfo(pathdata);
            var files = d.GetFiles("*.pdf");

            foreach (var filename in files)
            {
                Console.WriteLine(pathdata + filename.Name + ".pdf");
            }

            Console.ReadLine();
        }
    }
}

The above code does work (on my machine - that is my current IP address and a folder I have shared on my machine). Your code likely doesn't work for one of two reasons:

  1. Your path is not valid (eg using / instead of \\ )
  2. CBR folder is not shared

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM