C# CodeDom Cant type in " [closed] - c#

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I want to compile a code with codedom which should connect to my ftp server.
But I cant type in the credentials because of the ""...
Look here :
Temp.AppendLine(#"request.Credentials = new NetworkCredential("userid","userpassword");");
If I type " in the code, it automatic ends the content of the brackets...
Help?

You may need to escape the content by using double quotes, like this:
Temp.AppendLine(#"request.Credentials = new NetworkCredential(""userid"",""userpassword"");");

Temp.AppendLine(#"request.Credentials = new NetworkCredential(""userid"",""userpassword"");");
Escape the " with ""

Related

How can I get from a string of a directory and file name only the file name? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
The code:
'Files' is a List<string> and _indx is an int.
label22.Text = files[_indx];
For example in 'files' in index[0] I have this string:
D:\New folder (45)\converted.avi_Automatic\Lightning 0 Length 2 [91 - 93]\000091.bmp
But instead in label22.Text I want it to show me only '000091.bmp' without the rest of the directory path.
How can I do it ?
Use Path.GetFileName:
label22.Text = Path.GetFileName(files[_indx]);
I believe you are looking for Path.GetFileName():
label22.Text = Path.GetFileName(files[_indx]);
Path.GetFileName(fileName) returns the file name without the directory.
taken from http://msdn.microsoft.com/en-us/library/system.io.path.getfilename(v=vs.100).aspx
The simplest way is
Path.GetFileName(files[_indx]);

Converting C# line to VB.net [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I was trying to convert the following c# code to vb.net.
I see the problem is my lack of familiarity with the syntax of the parameters of OrderByDescending() What is the proper VB.Net equivalent of the C# line?
//C# code
SelectedFolder.Search("ALL", true).OrderByDescending(_ => _.Date).ToList();
//VB.Net part which doesn't work
For Each msg In SelectedFolder.Search("ALL", True).OrderByDescending(Function(_).[Date]).ToList()
After removing the underscore before [Date] the error became,
Error 1 Identifier expected.
The _ character is a line continuation in VB. Try changing the variable name to something more common, like x
For Each msg In SelectedFolder.Search("ALL", True).OrderByDescending(Function(x) x.[Date]).ToList()

Why am I getting a FileNotFoundException when the file is there? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I'm trying to save a file to the server and then load into a reader for it to be downloaded. However, I am getting a FileNotFoundExeption. I save to the exact same path, manually open the directory and can see the file there. However, reading it results in the exception. This is my first time trying his - am I doing something wrong?
try
{
using (StreamReader reader = new
StreamReader(HttpContext.Current.Server.MapPath(#"~/Downloads/data.text")))
{
// do something
}
}
catch (Exception)
{
}
Double-check the file name! In one of your comments you used the file name data.txt and not the name data.text. I suppose it's just a typo in your code.

what does format {0:x} mean? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I came across this C# literal and was wondering what does it mean?
Especially, in the following case:
string.Format("{0:x}", byteArray[i]);
Thanks
It means format the first argument (index 0) as hexadecimal: http://msdn.microsoft.com/en-us/library/s8s7t687(v=vs.80).aspx
It means the first argument will be output as hexadecimal (in lowercase !!).
To output uppercase you could use "{0:X}".
Look msdn for more info about string formatting : MSDN Custom string format
This represents the hexadecimal format.

explicitly casting generics in C# 4 [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
Can anyone help me in casting generic collection in c# 4.
Here is the code snippet.
GridView1.DataSource = dataServiceColl.Select(t => t.product_desc="EdibileItem")
It is throwing up runtime error at the below line,
Gridview1.Databind();
Saying it is a HTTP Exception.
I think it should be a simple type cast.
Thanks,
Kris.
Use
t => t.product_desc=="EdibileItem"
HTTP Exception? That has nothing to do with casting.
More importantly, why are you assigning "EdibleItem" to t.product_desc here?
Select(t => t.product_desc="EdibileItem")
Did you meant == instead of =? If so, would a Where be more appropriate than a Select?
I think it all boils down to: what are you trying to achieve, exactly?

Categories