Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. FileUpload + string!!

FileUpload + string!!

Scheduled Pinned Locked Moved ASP.NET
databasesysadminquestion
15 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
    string imagefolder = "photo";
    string savepath;
    string savefile;
    Label3.Text = "prefix";

    if (FileUpload1.HasFile)
    {
         string entryName = Label3.Text + 
             System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
    
         savepath = Path.Combine(Request.PhysicalApplicationPath, imagefolder);
         savefile = Path.Combine(savepath, FileUpload1.FileName);
    
         FileUpload1.PostedFile.SaveAs(Server.MapPath(entryName));
    
         AccessDataSource1.Insert();
    }
    

    }

    Can you put a breakpoint on the highlighted line and inspect the variable entryName and post it's value?

    I are Troll :suss:

    F Offline
    F Offline
    Farraj
    wrote on last edited by
    #3

    Hi Eddy thanks for ur replay Maybe i should get me a NON-Express edition of visual studio unfortunatly im using the express edition where i cant do that. if u think there is a way after all i'd love to know thanks for ur help brother !

    1 Reply Last reply
    0
    • L Lost User

      protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
      {
      string imagefolder = "photo";
      string savepath;
      string savefile;
      Label3.Text = "prefix";

      if (FileUpload1.HasFile)
      {
           string entryName = Label3.Text + 
               System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
      
           savepath = Path.Combine(Request.PhysicalApplicationPath, imagefolder);
           savefile = Path.Combine(savepath, FileUpload1.FileName);
      
           FileUpload1.PostedFile.SaveAs(Server.MapPath(entryName));
      
           AccessDataSource1.Insert();
      }
      

      }

      Can you put a breakpoint on the highlighted line and inspect the variable entryName and post it's value?

      I are Troll :suss:

      F Offline
      F Offline
      Farraj
      wrote on last edited by
      #4

      here i figured it out sorry! anyway the enteryname is "prefixidd9e1uDBJ-preview.jpg" as it should be, but at the database, its only the jpg name without the prefix

      L 1 Reply Last reply
      0
      • F Farraj

        here i figured it out sorry! anyway the enteryname is "prefixidd9e1uDBJ-preview.jpg" as it should be, but at the database, its only the jpg name without the prefix

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #5

        What's the SQL of the AccessDataSource1.InsertCommand? Does it get the correct parameters?

        I are Troll :suss:

        F 1 Reply Last reply
        0
        • L Lost User

          What's the SQL of the AccessDataSource1.InsertCommand? Does it get the correct parameters?

          I are Troll :suss:

          F Offline
          F Offline
          Farraj
          wrote on last edited by
          #6
          L 1 Reply Last reply
          0
          • F Farraj
            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #7

            You got it working you said? The "Accessdatasource1"-control should have a property called "InsertCommand". That property holds an INSERT statement, in Sql-syntax. Since you said that the variables contain the correct value, I'm guessing that it must go wrong when writing to the database. That's the task of the Accessdatasource, hence we'd want to check that next :)

            I are Troll :suss:

            F 2 Replies Last reply
            0
            • L Lost User

              You got it working you said? The "Accessdatasource1"-control should have a property called "InsertCommand". That property holds an INSERT statement, in Sql-syntax. Since you said that the variables contain the correct value, I'm guessing that it must go wrong when writing to the database. That's the task of the Accessdatasource, hence we'd want to check that next :)

              I are Troll :suss:

              F Offline
              F Offline
              Farraj
              wrote on last edited by
              #8

              this is my insercommand

              InsertCommand="INSERT INTO [gallery] ([file], [about]) VALUES (?, ?)"

              and my insertparameters

              <InsertParameters>
              <asp:controlParameter Name="file" Type="String" ControlID="FileUpload1" PropertyName="FileName"/>
              <asp:controlParameter Name="about" Type="String" ControlID="txtBoxAbout" PropertyName="text" />
              </InsertParameters>

              what do u think i should do or add? thanks

              1 Reply Last reply
              0
              • L Lost User

                You got it working you said? The "Accessdatasource1"-control should have a property called "InsertCommand". That property holds an INSERT statement, in Sql-syntax. Since you said that the variables contain the correct value, I'm guessing that it must go wrong when writing to the database. That's the task of the Accessdatasource, hence we'd want to check that next :)

                I are Troll :suss:

                F Offline
                F Offline
                Farraj
                wrote on last edited by
                #9

                hmm.. any help please?

                L 1 Reply Last reply
                0
                • F Farraj

                  hmm.. any help please?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #10

                  How about pointing the parameter to that label?

                  <asp:controlParameter Name="about" Type="String" ControlID="txtBoxAbout" PropertyName="text" />

                  Now, when you click the button, update the label first;

                  protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
                  {
                  string imagefolder = "photo";
                  string savepath;
                  string savefile;
                  Label3.Text = "Bla" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);

                  Does that fix it?

                  I are Troll :suss:

                  F 1 Reply Last reply
                  0
                  • L Lost User

                    How about pointing the parameter to that label?

                    <asp:controlParameter Name="about" Type="String" ControlID="txtBoxAbout" PropertyName="text" />

                    Now, when you click the button, update the label first;

                    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
                    {
                    string imagefolder = "photo";
                    string savepath;
                    string savefile;
                    Label3.Text = "Bla" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);

                    Does that fix it?

                    I are Troll :suss:

                    F Offline
                    F Offline
                    Farraj
                    wrote on last edited by
                    #11

                    it didnt work. i also tried using the $ sign - ControlID="Label3$FileUpload1" and added <asp:ControlParameter Name="pre" Type="string" ControlID="Label3" PropertyName="text" /> still not working. this is driving me crazy.

                    L 1 Reply Last reply
                    0
                    • F Farraj

                      it didnt work. i also tried using the $ sign - ControlID="Label3$FileUpload1" and added <asp:ControlParameter Name="pre" Type="string" ControlID="Label3" PropertyName="text" /> still not working. this is driving me crazy.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #12

                      The idea was to point the parameter to the label; the Name should point to the parameter-name (that's "file", from your Sql statement), the ControlId should point to the control that you're binding the parameter to. The Label displays it's contents in a Text property, hence the binding;

                      <asp:ControlParameter ControlID="Label3" Name="file" PropertyName="Text" Type="String" />

                      Does the value of the label get set correctly?

                      I are Troll :suss:

                      F 1 Reply Last reply
                      0
                      • L Lost User

                        The idea was to point the parameter to the label; the Name should point to the parameter-name (that's "file", from your Sql statement), the ControlId should point to the control that you're binding the parameter to. The Label displays it's contents in a Text property, hence the binding;

                        <asp:ControlParameter ControlID="Label3" Name="file" PropertyName="Text" Type="String" />

                        Does the value of the label get set correctly?

                        I are Troll :suss:

                        F Offline
                        F Offline
                        Farraj
                        wrote on last edited by
                        #13

                        Hi Eddy, this didnt fix it. Any other ideas?

                        L 1 Reply Last reply
                        0
                        • F Farraj

                          Hi Eddy, this didnt fix it. Any other ideas?

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #14

                          don-basil wrote:

                          this didnt fix it. Any other ideas?

                          I'm out of idea's, maybe one of the ASP.NET guru's can help out :(

                          I are Troll :suss:

                          F 1 Reply Last reply
                          0
                          • L Lost User

                            don-basil wrote:

                            this didnt fix it. Any other ideas?

                            I'm out of idea's, maybe one of the ASP.NET guru's can help out :(

                            I are Troll :suss:

                            F Offline
                            F Offline
                            Farraj
                            wrote on last edited by
                            #15

                            well, Eddy! i thank you ALOTTT for your time and help. u are great. if i ever get this solved i'll post it in here:) thanks again

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups