By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,681 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,681 IT Pros & Developers. It's quick & easy.

Putting data in different folders depending upon condition using web services

100+
P: 121
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
Jan 26 '09 #1
Share this Question
Share on Google+
9 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Seems pretty straightforward to me:

If myXMLFileIsValid 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.
Jan 26 '09 #2

100+
P: 121
thanks Frinavale,
that was a solution but i am still getting an error as

The target file "C:\abc\def\Desktop\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

Expand|Select|Wrap|Line Numbers
  1. File.Copy("Sendto\\" + FileName + ".xml", @"C:\abc\def\Desktop\XML\sent", Convert.ToBoolean(8));
Jan 27 '09 #3

P: 19
use
File.Copy( server.mathpad("locations")
Jan 27 '09 #4

Frinavale
Expert Mod 5K+
P: 9,731
@amirghaffarie1362
I think you meant to say Server.MapPath("locations")


Try the following:
Expand|Select|Wrap|Line Numbers
  1. File.Copy("Sendto\\" + FileName + ".xml", @"C:\abc\def\Desktop\XML\sent\"+ FileName + ".xml", Convert.ToBoolean(8));
Jan 27 '09 #5

Curtis Rutland
Expert 2.5K+
P: 3,256
Well, here's an easy way to do this:
Expand|Select|Wrap|Line Numbers
  1. string senttoDir = Server.MapPath("~/sentto/"); //this should be the relative path to your sentto dir
  2. string sentDir = Server.MapPath("~/sent/");//this should be the relative path to your sent dir
  3. FileInfo file = new FileInfo(senttoDir + FileName); //assuming you have declared FileName somewhere else
  4. 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
Expand|Select|Wrap|Line Numbers
  1. Convert.ToBoolean(8)
? Shouldn't that just be true?
Jan 27 '09 #6

100+
P: 121
that
Expand|Select|Wrap|Line Numbers
  1. convert.boolean(8) 
is if that directory doesnt exist , it will create it first and then put this file in it
Jan 27 '09 #7

Curtis Rutland
Expert 2.5K+
P: 3,256
I understand what that particular argument does, but Convert.ToBoolean(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.
Jan 27 '09 #8

100+
P: 121
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.
Jan 27 '09 #9

Curtis Rutland
Expert 2.5K+
P: 3,256
OK, I thought this was ASP.NET...so Server.MapPath won't work.

Here's my sample revised for desktop:
Expand|Select|Wrap|Line Numbers
  1. //make these global variables
  2. string senttoDir = @"C:\abc\def\Desktop\XML\sentto";
  3. string sentDir = @"C:\abc\def\Desktop\XML\sent";
  4.  
  5. //put this where you want to do the move
  6. FileInfo file = new FileInfo(senttoDir + FileName); //assuming you have declared FileName somewhere else
  7. 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.
Jan 27 '09 #10

Post your reply

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