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. urgent copy image from hard Drive on local host

urgent copy image from hard Drive on local host

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelpquestion
11 Posts 4 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.
  • M Offline
    M Offline
    mavii
    wrote on last edited by
    #1

    i am developing application in ASP.Net with C#. i am using button for FileOpenDialog to browse any image from hard drive as follows openFileDialog1.ShowDialog(); string s = openFileDialog1.FileName; textBox6.Text = s; problem is: i want the browsed image to be copied in local hosti.e,""C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg" i have the follwing idea in mind File.Copy("C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg", "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); or File.Copy(s.Substring(13,s.Length-13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); but i dont want to existing image to be overwrite, i want all images to ve saved in local host can anyone sugesst me what to do?

    S A 2 Replies Last reply
    0
    • M mavii

      i am developing application in ASP.Net with C#. i am using button for FileOpenDialog to browse any image from hard drive as follows openFileDialog1.ShowDialog(); string s = openFileDialog1.FileName; textBox6.Text = s; problem is: i want the browsed image to be copied in local hosti.e,""C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg" i have the follwing idea in mind File.Copy("C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg", "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); or File.Copy(s.Substring(13,s.Length-13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); but i dont want to existing image to be overwrite, i want all images to ve saved in local host can anyone sugesst me what to do?

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      But what if the user(client) wants to copy a file from its machine to server

      Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

      M 1 Reply Last reply
      0
      • S Sandeep Akhare

        But what if the user(client) wants to copy a file from its machine to server

        Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

        M Offline
        M Offline
        mavii
        wrote on last edited by
        #3

        but my requirement is that in Windows application user is browsing image and clicking the "save" button to save it in database, i have to lauch the same image in website to i want the image to be copied in local host, can u suggest any solution for that

        S N 2 Replies Last reply
        0
        • M mavii

          but my requirement is that in Windows application user is browsing image and clicking the "save" button to save it in database, i have to lauch the same image in website to i want the image to be copied in local host, can u suggest any solution for that

          S Offline
          S Offline
          Sandeep Akhare
          wrote on last edited by
          #4

          mavii wrote:

          my requirement is that in Windows application user

          But in your first query you posted that you are developing asp.net application . i don't have much idea about that but post your queries in right forum

          Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

          1 Reply Last reply
          0
          • M mavii

            i am developing application in ASP.Net with C#. i am using button for FileOpenDialog to browse any image from hard drive as follows openFileDialog1.ShowDialog(); string s = openFileDialog1.FileName; textBox6.Text = s; problem is: i want the browsed image to be copied in local hosti.e,""C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg" i have the follwing idea in mind File.Copy("C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg", "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); or File.Copy(s.Substring(13,s.Length-13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); but i dont want to existing image to be overwrite, i want all images to ve saved in local host can anyone sugesst me what to do?

            A Offline
            A Offline
            APDevelop
            wrote on last edited by
            #5

            As you are creating an ASP.NET application so I would suggest you to use FileUpload control to upload the said file to your server’s working directory. Here is a small example which does that: protected void UploadButton_Click(object sender, EventArgs e) { if(FileUploadControl.HasFile) { try { if(FileUploadControl.PostedFile.ContentType == "image/jpeg") { if(FileUploadControl.PostedFile.ContentLength < 102400) { string filename = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath("~/") + filename); StatusLabel.Text = "Upload status: File uploaded!"; } else StatusLabel.Text = "Upload status: The file has to be less than 100 kb!"; } else StatusLabel.Text = "Upload status: Only JPEG files are accepted!"; } catch(Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } }

            Regards, Amit Pal

            M 1 Reply Last reply
            0
            • A APDevelop

              As you are creating an ASP.NET application so I would suggest you to use FileUpload control to upload the said file to your server’s working directory. Here is a small example which does that: protected void UploadButton_Click(object sender, EventArgs e) { if(FileUploadControl.HasFile) { try { if(FileUploadControl.PostedFile.ContentType == "image/jpeg") { if(FileUploadControl.PostedFile.ContentLength < 102400) { string filename = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath("~/") + filename); StatusLabel.Text = "Upload status: File uploaded!"; } else StatusLabel.Text = "Upload status: The file has to be less than 100 kb!"; } else StatusLabel.Text = "Upload status: Only JPEG files are accepted!"; } catch(Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } }

              Regards, Amit Pal

              M Offline
              M Offline
              mavii
              wrote on last edited by
              #6

              but my requirement is that in Windows application user is browsing image and clicking the "save" button to save it in database, i have to lauch the same image in website to i want the image to be copied in local host "Server.MapPath" doesent work in Wndows application

              1 Reply Last reply
              0
              • M mavii

                but my requirement is that in Windows application user is browsing image and clicking the "save" button to save it in database, i have to lauch the same image in website to i want the image to be copied in local host, can u suggest any solution for that

                N Offline
                N Offline
                N a v a n e e t h
                wrote on last edited by
                #7

                mavii wrote:

                but my requirement is that in Windows application user is browsing image and clicking the "save" button to save it in database,

                Is images are stored in database ?

                mavii wrote:

                i have to lauch the same image in website to i want the image to be copied in local host, can u suggest any solution for that

                Still I am not getting what you mean by this. 1 - Why user is browsing image from an windows application 2 - From where the user comes ? If the user is coming from another system, how can you copy the file to your local drive ? Please make your question more clear


                My Website | Ask smart questions

                M 1 Reply Last reply
                0
                • N N a v a n e e t h

                  mavii wrote:

                  but my requirement is that in Windows application user is browsing image and clicking the "save" button to save it in database,

                  Is images are stored in database ?

                  mavii wrote:

                  i have to lauch the same image in website to i want the image to be copied in local host, can u suggest any solution for that

                  Still I am not getting what you mean by this. 1 - Why user is browsing image from an windows application 2 - From where the user comes ? If the user is coming from another system, how can you copy the file to your local drive ? Please make your question more clear


                  My Website | Ask smart questions

                  M Offline
                  M Offline
                  mavii
                  wrote on last edited by
                  #8

                  actually i am developing two applications for the same organization using a single database, i am saving the record of "Wanted Criminals" in my wndowos application. the user of windows application opens a page to insert the record of new criminal, user also saves the picture of criminal using "FileOpenDialog" to browse any image saved in hard drive, so in database the path of "wanted criminal" is saved along with criminal names, age etc. problem is that in my website i want to display the picture of "Wanted criminal" along with his other information in da Datagrid, but in databast the path of Picture is saved as "E:\criminals\abc.jpg". website can display images placed in local host, so i wanted the image whom path is being saved in database through windows application should be copied with same name in "C:\Inetpub\www.root" have u got my problem can u plz suggest any solution?

                  N 1 Reply Last reply
                  0
                  • M mavii

                    actually i am developing two applications for the same organization using a single database, i am saving the record of "Wanted Criminals" in my wndowos application. the user of windows application opens a page to insert the record of new criminal, user also saves the picture of criminal using "FileOpenDialog" to browse any image saved in hard drive, so in database the path of "wanted criminal" is saved along with criminal names, age etc. problem is that in my website i want to display the picture of "Wanted criminal" along with his other information in da Datagrid, but in databast the path of Picture is saved as "E:\criminals\abc.jpg". website can display images placed in local host, so i wanted the image whom path is being saved in database through windows application should be copied with same name in "C:\Inetpub\www.root" have u got my problem can u plz suggest any solution?

                    N Offline
                    N Offline
                    N a v a n e e t h
                    wrote on last edited by
                    #9

                    mavii wrote:

                    user also saves the picture of criminal using "FileOpenDialog" to browse any image saved in hard drive, so in database the path of "wanted criminal" is saved along with criminal names, age etc.

                    Problem resides here. Because the file is in remote machine who uses the windows application. And you are trying to see that in your local ASP.NET application. This is not possible since you don't have a virtual path access to the file. Copying file from that machine to local machine is also not a good solution. You can solve this by keeping image in database as BLOB data. Check this[^] to get started with that. Hope this helps


                    My Website | Ask smart questions

                    M 2 Replies Last reply
                    0
                    • N N a v a n e e t h

                      mavii wrote:

                      user also saves the picture of criminal using "FileOpenDialog" to browse any image saved in hard drive, so in database the path of "wanted criminal" is saved along with criminal names, age etc.

                      Problem resides here. Because the file is in remote machine who uses the windows application. And you are trying to see that in your local ASP.NET application. This is not possible since you don't have a virtual path access to the file. Copying file from that machine to local machine is also not a good solution. You can solve this by keeping image in database as BLOB data. Check this[^] to get started with that. Hope this helps


                      My Website | Ask smart questions

                      M Offline
                      M Offline
                      mavii
                      wrote on last edited by
                      #10

                      ur idea must be right but i cant try it now, i have tried a method, can u plz suggest solution regarding this problem openFileDialog1.ShowDialog(); string s = openFileDialog1.FileName; textBox6.Text = s; string st = "abc1" + (count++) + ".jpg"; File.Copy(s.Substring(13, s.Length - 13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\" + st); the subctring exactly returns the name og the picture PROBLEM IS: i want the image to be saved with the same name in local host as the Substing retun name "ABC.jpg" i want to save it with the same name in local host

                      1 Reply Last reply
                      0
                      • N N a v a n e e t h

                        mavii wrote:

                        user also saves the picture of criminal using "FileOpenDialog" to browse any image saved in hard drive, so in database the path of "wanted criminal" is saved along with criminal names, age etc.

                        Problem resides here. Because the file is in remote machine who uses the windows application. And you are trying to see that in your local ASP.NET application. This is not possible since you don't have a virtual path access to the file. Copying file from that machine to local machine is also not a good solution. You can solve this by keeping image in database as BLOB data. Check this[^] to get started with that. Hope this helps


                        My Website | Ask smart questions

                        M Offline
                        M Offline
                        mavii
                        wrote on last edited by
                        #11

                        can u suggest a solution for following problem public static int count = 0; private void button3_Click_1(object sender, EventArgs e) { openFileDialog1.ShowDialog(); string s = openFileDialog1.FileName; textBox6.Text = s; string st = "Pict" + (count++) + ".jpg"; File.Copy(s.Substring(13, s.Length - 13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\" + st);} i want the image to be saved in local host with the same name as as it was present in hard drive (from where it was browsed) ur solution regarding BLOB must be right but i cant apply it right now:(

                        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