Changing URL string before inserting with C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Eyadtrabulsi
    New Member
    • Mar 2007
    • 40

    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
  • avkdsiva
    New Member
    • Mar 2007
    • 23

    #2
    Page.Response.R edirect(@"Dir1\ Dir2\Mypage.asp x")
    or
    Page.Response.R edirect("Dir1\\ Dir2\\Mypage.as px")

    Comment

    • Eyadtrabulsi
      New Member
      • Mar 2007
      • 40

      #3
      Thank you very much for your answer, but I mean Image URL not the page's one
      I used "C:\dir1\dir2\i mage.jpg"
      but it didn't work, so I tried "\\\C:\dir1\dir 2\image.jpg"
      it worked..!!!!

      Anyway, if I can edit the text after retriving it by using Server.MapPath, it would give me more flexibility...

      Comment

      • Eyadtrabulsi
        New Member
        • Mar 2007
        • 40

        #4
        Please someone helps me... I'm still waiting!!

        Comment

        • avkdsiva
          New Member
          • Mar 2007
          • 23

          #5
          protected void Page_Load(objec t sender, System.EventArg s e)
          {
          // Put user code to initialize the page here
          Image1.ImageUrl = Server.MapPath( "..\\Images\\Ba nkName.JPEG");
          }

          I did this way and it is working. Please tell me if I am misinterpreting the question.

          Comment

          • Eyadtrabulsi
            New Member
            • Mar 2007
            • 40

            #6
            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.GetFi les(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;

            ContentPlaceHol der3.Controls.A dd(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\showro om\My Documents\Visua l Studio 2005\HorseClub\ pics\horses\ceb it.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??

            Comment

            • avkdsiva
              New Member
              • Mar 2007
              • 23

              #7
              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?
              :)

              Comment

              • Eyadtrabulsi
                New Member
                • Mar 2007
                • 40

                #8
                Sorry :-(
                it gave the same results...

                Comment

                • Eyadtrabulsi
                  New Member
                  • Mar 2007
                  • 40

                  #9
                  but you know!!? such a format like this worked with ImageURL address:

                  \\\C:\Documents and Settings\showro om\My Documents\Visua l Studio 2005\HorseClub\ pics\horses\ceb it.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...

                  Comment

                  • Eyadtrabulsi
                    New Member
                    • Mar 2007
                    • 40

                    #10
                    Please someone gives more attention to my request, it very close to be solved...

                    Comment

                    • Eyadtrabulsi
                      New Member
                      • Mar 2007
                      • 40

                      #11
                      Isn't there anyway to insert \ backslash into string with C#
                      This is the second community which stoped responding at this point

                      Comment

                      • avkdsiva
                        New Member
                        • Mar 2007
                        • 23

                        #12
                        string[] imgs = Directory.GetFi les("E:\\Projec ts\\Banking\\Im ages", "*.jpg");
                        foreach (string img in imgs)
                        ImageButton1.Im ageUrl = img ;

                        The above code is working fine.... I am not able to reproduce your problem.

                        Comment

                        • SammyB
                          Recognized Expert Contributor
                          • Mar 2007
                          • 807

                          #13
                          Originally posted by Eyadtrabulsi
                          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:
                          Code:
                          MessageBox.Show(@"\\\C:\Documents and Settings\showroom\My Documents\Visual Studio 2005\HorseClub\pics\horses\cebit.jpg");

                          Comment

                          Working...