Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8742905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:34:59+00:00 2026-06-13T11:34:59+00:00

I have this method: private List<string> offline(string targetDirectory) { if (targetDirectory.Contains(http://)) { MessageBox.Show(true); }

  • 0

I have this method:

private List<string> offline(string targetDirectory)
{
    if (targetDirectory.Contains("http://"))
    {
        MessageBox.Show("true");
    }
    DirectoryInfo di = new DirectoryInfo(targetDirectory);
    List<string> directories = new List<string>();

    try
    {
        string[] dirs = Directory.GetDirectories(targetDirectory,"*.*",SearchOption.TopDirectoryOnly);
        for (int i = 0; i < dirs.Length; i++)
        {
            string t = "http://" + dirs[i];
            directories.Add(t);
        }
    }
    catch
    {
        MessageBox.Show("hgjghj");
    }


    return directories;

}

This is the part:

if (targetDirectory.Contains("http://"))
{
     MessageBox.Show("true");
}

I’m getting a directory which give me all the directories in this directory and I’m adding to each directory the string "http://".

The problem is when next time a directory is getting to the function its coming with "http://"

For example: http://c:\\ or http://c:\\windows

And then the line

 DirectoryInfo di = new DirectoryInfo(targetDirectory); // throws exception.

So I want that each time a directory is getting to the function to check if it starts with "http://" in the beginning, strip the "http://" part, get all the directories, and then add to each directory "http://" like now.

How can I remove "http://"?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:34:59+00:00Added an answer on June 13, 2026 at 11:34 am

    I would be stricter than using Contains – I’d use StartsWith, and then Substring:

    if (targetDirectory.StartsWith("http://"))
    {
        targetDirectory = targetDirectory.Substring("http://".Length);
    }
    

    Or wrap it in a helper method:

    public static string StripPrefix(string text, string prefix)
    {
        return text.StartsWith(prefix) ? text.Substring(prefix.Length) : text;
    }
    

    It’s not clear to me why you’re putting the http:// as a prefix anyway though, to be honest. I can’t see how you’d expect a directory name prefixed with http:// to be a valid URL. Perhaps if you could explain why you’re doing it, we could suggest a better approach.

    (Also, I really hope you don’t have a try/catch block like that in your real code, and that normally you follow .NET naming conventions.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method: private List<String> userCns = Collections.synchronizedList(new ArrayList<String>()); private List<String> recipients =
I have a web service that contains this method: [WebMethod] public static List<string> GetFileListOnWebServer()
I have this method to transfer files using a FTP Server: private void TransferNeededFiles(IEnumerable<string>
I have this recursive method which deletes empty folders: private void DeleteEmpty(DirectoryInfo directory) {
I have this code: private List<string> webCrawler(string url, int levels) { HtmlAgilityPack.HtmlDocument doc; HtmlWeb
I have this method which return an array of string : private static string[]
I have this method signature: List<ITMData> Parse(string[] lines) ITMData has 35 properties. How would
I have this method I wrote as: private void GetReceivedInvoiceTasks(User user, List<Task> tasks) {
I have a method private static DataTable ParseTable(HtmlNode table) and sometimes this method has
I have this method to display the contact numbers in my inbox: public ArrayList<String>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.