469,299 Members | 2,081 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

Changing URL string before inserting with C#

Hello, I'm new member, Please someone help me..

I got image's address using Server.MapPath and returned it to .ImageURL of the ImageButton but it didn't work
I noticed later that if I added \\\ 3 backslashs "as a string" at the bigining of the address it would work properly, so is there anyway to add backslash to a STRING in C#, because the compiler doesn't accept any backslash in "\\\" string formats
Or how could we edit string properly before we insert it into address
and what is the exact format of ImageURL strings
Mar 13 '07 #1
12 2205
Page.Response.Redirect(@"Dir1\Dir2\Mypage.aspx")
or
Page.Response.Redirect("Dir1\\Dir2\\Mypage.aspx")
Mar 13 '07 #2
Thank you very much for your answer, but I mean Image URL not the page's one
I used "C:\dir1\dir2\image.jpg"
but it didn't work, so I tried "\\\C:\dir1\dir2\image.jpg"
it worked..!!!!

Anyway, if I can edit the text after retriving it by using Server.MapPath, it would give me more flexibility...
Mar 13 '07 #3
Please someone helps me... I'm still waiting!!
Mar 14 '07 #4
protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Image1.ImageUrl = Server.MapPath("..\\Images\\BankName.JPEG");
}

I did this way and it is working. Please tell me if I am misinterpreting the question.
Mar 15 '07 #5
Thanks for you reply, but I would let you know what exactly I'm trying to do..

I have directory which contains all images I'm automating displaying them, by searching for them and returning them in an array to present them on my webpage
here is the code



int i = 0;
// get the address of the directory, then seach for files with .JPG extension inside
string add = Server.MapPath("pics//horses//");
string[] images = Directory.GetFiles(add , "*.jpg");

// Create ImageButton Array, and use it to store & present result images in determine specifications
ImageButton[] imageBtt = new ImageButton[images.Length];
foreach (string image in images)
{
Label1.Text += image;
imageBtt[i] = new ImageButton();
imageBtt[i].Width = 70;
imageBtt[i].Height = 47;
imageBtt[i].ID = "imageBtt" + i;
imageBtt[i].Visible = true;
imageBtt[i].ImageUrl = image;

ContentPlaceHolder3.Controls.Add(imageBtt[i]);
i++;
}


I used Lable1 to know exactly what is the address returning by this code, its correct as it's shown below:

C:\Documents and Settings\showroom\My Documents\Visual Studio 2005\HorseClub\pics\horses\cebit.jpg

but it's not showing the images by the ImageButtons, I'm wondering if it's because of the address format. What do you think??
Mar 15 '07 #6
One simple (may be silly as well) question.
Can you modify the below line
string add = Server.MapPath("pics//horses//");
as
string add = Server.MapPath("pics\\horses\\");

and see what happens?
:)
Mar 15 '07 #7
Sorry :-(
it gave the same results...
Mar 15 '07 #8
but you know!!? such a format like this worked with ImageURL address:

\\\C:\Documents and Settings\showroom\My Documents\Visual Studio 2005\HorseClub\pics\horses\cebit.jpg

but I tried to add "\\\" to the begining of the address before inserting it into ImageURL but it didn't work, maybe the compiler rejects such a character \ as a string...
Mar 15 '07 #9
Please someone gives more attention to my request, it very close to be solved...
Mar 17 '07 #10
Isn't there anyway to insert \ backslash into string with C#
This is the second community which stoped responding at this point
Mar 19 '07 #11
string[] imgs = Directory.GetFiles("E:\\Projects\\Banking\\Images" , "*.jpg");
foreach (string img in imgs)
ImageButton1.ImageUrl = img ;

The above code is working fine.... I am not able to reproduce your problem.
Mar 20 '07 #12
SammyB
807 Expert 512MB
Isn't there anyway to insert \ backslash into string with C#
This is the second community which stoped responding at this point
But, we didn't stop responding! ;o)

There are two ways to insert a backslash:
  1. As Avkdsiva did, you use two backslashes
  2. But, that gets messy: if you have three backslashes, you have to use six. So, if you place an @ before the first quote, then you can place backslashes in the string:
Expand|Select|Wrap|Line Numbers
  1. MessageBox.Show(@"\\\C:\Documents and Settings\showroom\My Documents\Visual Studio 2005\HorseClub\pics\horses\cebit.jpg");
Mar 20 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Danny Anderson | last post: by
5 posts views Thread by MaSTeR | last post: by
7 posts views Thread by .Net Sports | last post: by
reply views Thread by mannux | last post: by
9 posts views Thread by jy836 | last post: by
7 posts views Thread by Matt | last post: by
4 posts views Thread by yaru22 | last post: by
3 posts views Thread by =?Utf-8?B?ZGVlcGFr?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.