Putting data in different folders depending upon condition using web services

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jay123
    New Member
    • Sep 2008
    • 121

    Putting data in different folders depending upon condition using web services

    hi all,
    what i am trying to do is i have three folders
    1) sentto
    2) error
    3) sent

    i am using web services in which we give the name of XML file ( which is in sentto folder. when the name is given , my web service validates it with a schema and now according to result(which is validated or not-validated). i want to shift that XML file to error folder( if not validated) or sent folder ( if validated) . when this file is shifted the original file should be deleted.

    I have created a web-service which performs this action, now how to put this XML file into error or sent folder depending on condition.

    any help wil be appreciated.

    Thanks in advance
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Seems pretty straightforward to me:

    If myXMLFileIsVali d Then
    --> Move the File to the Sent Folder
    Else
    --> Move the File to the Error Folder
    End If

    To move a file use the System.IO.File. Move() method.

    Comment

    • jay123
      New Member
      • Sep 2008
      • 121

      #3
      thanks Frinavale,
      that was a solution but i am still getting an error as

      The target file "C:\abc\def\Des ktop\XML\Sent" is a directory, not a file.

      as i want to save my Xml file to folder sent.

      any suggestions?

      below is the file.copy command i have used

      Code:
      File.Copy("Sendto\\" + FileName + ".xml", @"C:\abc\def\Desktop\XML\sent", Convert.ToBoolean(8));

      Comment

      • amirghaffarie1362
        New Member
        • Jan 2009
        • 19

        #4
        use
        File.Copy( server.mathpad( "locations" )

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by amirghaffarie13 62
          use
          File.Copy( server.mathpad( "locations" )
          I think you meant to say Server.MapPath( "locations" )


          Try the following:
          Code:
          File.Copy("Sendto\\" + FileName + ".xml", @"C:\abc\def\Desktop\XML\sent\"+ FileName + ".xml", Convert.ToBoolean(8));

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            Well, here's an easy way to do this:
            Code:
            string senttoDir = Server.MapPath("~/sentto/"); //this should be the relative path to your sentto dir
            string sentDir = Server.MapPath("~/sent/");//this should be the relative path to your sent dir
            FileInfo file = new FileInfo(senttoDir + FileName); //assuming you have declared FileName somewhere else
            file.MoveTo(sentDir + FileName);
            FileInfo and DirectoryInfo are your best friends for file and directory operations. Both are part of the System.IO namespace.

            EDIT:
            I'm curious, why are you using
            Code:
            Convert.ToBoolean(8)
            ? Shouldn't that just be true?

            Comment

            • jay123
              New Member
              • Sep 2008
              • 121

              #7
              that
              Code:
              convert.boolean(8)
              is if that directory doesnt exist , it will create it first and then put this file in it

              Comment

              • Curtis Rutland
                Recognized Expert Specialist
                • Apr 2008
                • 3264

                #8
                I understand what that particular argument does, but Convert.ToBoole an(8) is equal to true so why not just use true?

                Anyway, try my example, or Frinny's and let us know what happens.

                My example is more portable, so if you ever move it off your desktop and onto a web server, you won't have to manually change the paths.

                Comment

                • jay123
                  New Member
                  • Sep 2008
                  • 121

                  #9
                  actually i am writing console application , so the path will always be in setting folder. actually initially i was using only 8 and i was getting an error of can't convert int to bool so i just added convert.bool to it.

                  Comment

                  • Curtis Rutland
                    Recognized Expert Specialist
                    • Apr 2008
                    • 3264

                    #10
                    OK, I thought this was ASP.NET...so Server.MapPath won't work.

                    Here's my sample revised for desktop:
                    Code:
                    //make these global variables
                    string senttoDir = @"C:\abc\def\Desktop\XML\sentto";
                    string sentDir = @"C:\abc\def\Desktop\XML\sent";
                    
                    //put this where you want to do the move
                    FileInfo file = new FileInfo(senttoDir + FileName); //assuming you have declared FileName somewhere else
                    file.MoveTo(sentDir + FileName);
                    As to the bool thing, I don't know why you think you have to use 8. Bools can only be true/false, so just use true.

                    Comment

                    Working...