hii want read a link from file and use it with the extension of the link ,
the file contain :

and i wanna use it like this:

StreamReader rr = new StreamReader("link.txt");
string sor = rr.ReadLine();
url = "sor+"resources/stdInfo/authenticate/" + tx.Text + "/" + passwordBox1.Password+ "/1/570322308ce1121cba1b93f5acc9ebd4733ef2bca90ef942a2cfa224f0aa08dc/1";


the red : mean the string wich i put into it what i've read from file the green : mean that there's a mistake but i dont know what it's?!! any one can help

Dani AI

Generated

Short answer: is right — the variable name must not be wrapped in quotes. Beyond that, common pitfalls are: the file contains HTML (not a raw URL), the read string has extra whitespace or a BOM, the runtime's working directory is different than you expect, and concatenation can produce double slashes or leave characters unencoded.

Use a simple, defensive workflow: read the file, trim it, normalize the trailing slash, URL-encode user-provided segments, then combine. File.ReadAllText is a safe one-line reader for small files (see the docs) and Uri.EscapeDataString will keep user values safe for a path segment.

var baseUrl = File.ReadAllText(pathToFile).Trim();
if (baseUrl.EndsWith("/")) baseUrl = baseUrl.TrimEnd('/');
var endpoint = $"api/endpoint/{Uri.EscapeDataString(username)}/{Uri.EscapeDataString(password)}";
var fullUrl = baseUrl + "/" + endpoint;

If the file actually contains an HTML anchor instead of a bare URL, extract the href rather than using the whole line. A quick approach is a Regex match for href="..." (or use an HTML parser for robustness):

var raw = File.ReadAllText(pathToFile);
var m = Regex.Match(raw, "href\\s*=\\s*\"([^\"]+)\"", RegexOptions.IgnoreCase);
if (m.Success) baseUrl = m.Groups[1].Value.Trim();

If this runs in ASP.NET, resolve the disk path with Server.MapPath; in a desktop app use the app base directory. Also avoid putting plaintext passwords in URLs — prefer HTTPS and POST or token-based auth, and always encode path parts with Uri.EscapeDataString. For references: File.ReadAllText (https://learn.microsoft.com/en-us/dotnet/api/system.io.file.readalltext?view=netframework-4.8), Regex (https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex?view=netframework-4.8), Server.MapPath (https://learn.microsoft.com/en-us/dotnet/api/system.web.httpserverutility.mappath?view=netframework-4.8), and Uri.EscapeDataString (https://learn.microsoft.com/en-us/dotnet/api/system.uri.escapedatastring?view=netframework-4.8).

You have sor in quotes for a start. Is that a typo or part of your code because it, at the very least, should be:

url = sor + "resources/stdInfo/authenticate/" + tx.Text + "/" + passwordBox1.Password+ "/1/570322308ce1121cba1b93f5acc9ebd4733ef2bca90ef942a2cfa224f0aa08dc/1";

commented: thanx alot:) +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.