It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have
C:\Softwares\Test\ASPnetTest\Project11\Shared\Public\Images\
How to convert it to
Shared\Public\Images\
Thank you.
If you want the path as used in a URL:
You can use something like this (classes are valid in C# too): http://geekswithblogs.net/AlsLog/archive/2006/08/03/87032.aspx
Public Function MapURL(ByVal Path As String) As String
Dim AppPath As String = _
HttpContext.Current.Server.MapPath("~")
Dim url As String = String.Format("~{0}" _
, Path.Replace(AppPath, "").Replace("\", "/"))
Return url
End Function
...To make it easy:
private static string MapUrl(string path)
{
var appPath = HttpContext.Current.Server.MapPath("~");
return string.Format("~{0}", path.Replace(appPath, "").Replace("\\", "/"));
}
If you want the folder, relative to your app's base path:
http://msdn.microsoft.com/en-us/library/system.web.httprequest.physicalapplicationpath.aspx
Request.PhysicalApplicationPath will give you the c:\softwares\test\aspnettest\project11 part. Then you can get the relative part, see this answer here for that:
How to get relative path from absolute path
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
System.Web.HttpUtility.HtmlDecode not working for test %3cstrong%3ebold %3c/strong%3etest
Output should be <strong>bold </strong>test
I believe you want HttpUtility.UrlDecode in this case.
HtmlDecode is for things like <strong>
You are mixing up html encoding with url encoding. So it is normal that this does not work. Try using HttpUtility.UrlDecode()
Example for Url encoding:
%3cstrong%3ebold%3c/strong%3e
Example for HTML encoding:
<strong>bold</strong>
HttpUtility.HtmlDecode is used for converting HTML entities, e.g.
var sample = "<strong>bold </strong>test";
var result = HttpUtility.HtmlDecode(sample);
// result = "<strong>bold </strong>test"
You're looking for HttpUtility.UrlDecode, I believe, which surrenders:
var sample = "test %3cstrong%3ebold %3c/strong%3etest";
var result = HttpUtility.UrlDecode(sample);
// result = "<strong>bold </strong>test"
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How can I do the following in C# :
var re = /^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$/;
re.test('2013/03/05 15:22:00'); // returns true
You can use the Regex.IsMatch instead (docs).
Regex.IsMatch("2013/03/05 15:22:00", #"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$"); // true if match
The below code should get you where you want to be.
Regex rx = new Regex(#"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$");
String test = "2013/03/05 15:22:00";
if (rx.IsMatch(test))
{
//Test String matches
}
else
{
//Test String does not match
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm trying to put this string in my resources:
Environment.CurrentDirectory + \\Server Files\\
But whenever I load the string, the Environment.CurrentDirectory part is shown as normal text instead of the current directory path :(.
Example:
Console.WriteLine(Resources.ServerFilesLocation); // Doesn't give me a path, but just plain text.
Any runtime environment value cannot be stored as a string in resources. What you should do is create a layer between. Something like:
static class ResourceManager
{
public static string ServerFilesLocation {
get {
return String.Format(Resources.ServerFilesDirectory, Environment.CurrentDirectory);
// ServerFilesDirectory = "{0}\\Server Files\\" or something similar
}
}
}
And use it like: Console.WriteLine(ResourceManager.ServerFilesLocation);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have an array of words and I want to remove them from an input string, could anyone tell me what is the better way to conduct this task?
This should work
string[] arrToCheck = new string[] { "try ", "yourself", "before " };
string input = "Did you try this yourself before asking";
foreach (string word in arrToCheck )
{
input = input.Replace(word, "");
}
MessageBox.Show("result is "+input);
input variable will now have a string which does not have those words in your array.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I'm working on something like recycle bin, that I need to move folder/files to already existing folder, I tried to use
Directory.Move
but it creates new directory and that's wrong for me, I have a specific directory to move to.
Can you help me?
It seems do don't actually want to move the folder, you want to move the contents of the folder. If you want to do that, you have to tell the computer to do that:
void MoveContentsOfDirectory(string source, string target)
{
foreach (var file in Directory.EnumerateFiles(source))
{
var dest = Path.Combine(target, Path.GetFileName(file));
File.Move(file, dest);
}
foreach (var dir in Directory.EnumerateDirectories(source))
{
var dest = Path.Combine(target, Path.GetFileName(dir));
Directory.Move(dir, dest);
}
// optional
Directory.Delete(source);
}