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
9 1522 Frinavale 9,735
Recognized Expert Moderator Expert
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.
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 - File.Copy("Sendto\\" + FileName + ".xml", @"C:\abc\def\Desktop\XML\sent", Convert.ToBoolean(8));
use
File.Copy( server.mathpad("locations")
Frinavale 9,735
Recognized Expert Moderator Expert @amirghaffarie1362
I think you meant to say Server.MapPath("locations")
Try the following: - File.Copy("Sendto\\" + FileName + ".xml", @"C:\abc\def\Desktop\XML\sent\"+ FileName + ".xml", Convert.ToBoolean(8));
Well, here's an easy way to do this: - 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
? Shouldn't that just be true?
that
is if that directory doesnt exist , it will create it first and then put this file in it
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.
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.
OK, I thought this was ASP.NET...so Server.MapPath won't work.
Here's my sample revised for desktop: -
//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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Frnak McKenney |
last post by:
Back when computer dinosaurs roamed the earth and the precursors to
today's Internet were tiny flocks of TDMs living symbiotically with
the silicon giants, tracking access to data processing...
|
by: John Smith |
last post by:
How do I use two different data types with a conditional operator ?
I want to cout either a character or an integer depending on a
certain condition.
cout << ((IsThisTrue? char:integer)
The...
|
by: xixi |
last post by:
hi, we are using db2 udb v8.1 on win 64 bit with fp3 with type 4
db2jcc.jar driver.
when i execute this query ,
select id, arno01, arcd01, arno16, artx01, armo09, ardy09, arcc09,
aryr09,...
|
by: mr_mach7 |
last post by:
I have a situation in which I want to dynamically build a SQL
statement based upon criteria. The statement would contain different
fields depending upon the criteria. I created a Stored Procedure...
|
by: Arpan |
last post by:
The .NET Framework 2.0 documentation states that
An Object variable always holds a pointer to the data, never the data
itself.
Now w.r.t. the following ASP.NET code snippet, can someone please...
| |
by: sellcraig |
last post by:
Microsoft access
2 tables
table "data main" contains a field called "code"
table "ddw1" is created from a make table query of "data main"
Goal-
the data in "code" field in needs to...
|
by: C4rtm4N |
last post by:
I'm about to embark on re-writing a database & bespoke web reporting
application for our call centre & would like a little advice please.
Currently the database has 10 tables containing summaried...
|
by: db007 |
last post by:
I have a problem at the moment with a web project.
I have two Panels within an UpdatePanel on an aspx page (using Masterpages). I'm using ASP.Net 2.0 with an AJAX enabled website.
The two...
|
by: balabaster |
last post by:
Does anyone have experience integrating LINQ into SOA architecture. I've spent all night trawling through documents and books regarding this and I've come to the conclusion that I'm going about...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |