|
here is my code i used to copy the file, i get the same error any idea why ??
private void MoveFile()
{
System.IO.File.Copy(sourceFile, destFile, true);
if (System.IO.Directory.Exists(sourcePath))
{
string[] files = System.IO.Directory.GetFiles(sourcePath);
foreach (string s in files)
{
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
}
}
else
{
Console.WriteLine("Source path does not exist!");
}
}
|
|
|
|
|
Where does this break, and what is the message?
In the code:
shadowthief_03 wrote: foreach (string s in files)
{
// Use static Path methods to extract only the file name from the path.
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
}
Don't re-use the variables fileName or destFile , declare with different names, or you'll get the world of pain later.
There is a danger (in fact I *think* it is certain) that the loop above will re-copy the file copied in the first line inside the method you posted. You will get an access denied message if that file is marked as read only on the file system (i.e. recopying onto a readnly file already copied). You could try removing that line from the code.Antoine de Saint-Exupery: Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
|
|
|
|
|
wait i got it figured out you where right about the copy, and i wasn't using file.copy the right way thanks to everyone for your help i really appreciate it
|
|
|
|
|
shadowthief_03 wrote: here is my code i used to copy the file, i get the same error any idea why ??
It might be because there's already a file on your system. You're mentioning that you want to overwrite this file if it exists, in the File.Copy statement;
System.IO.File.Copy(s, destFile, true); This will fail with a "UnauthorizedAccessException" if there's a pre-existing file that's read-only. A file that has been copied from CD will have the read-only flag set, preventing it from being overwritten by a File.Copy .I are Troll
|
|
|
|
|
hi
How to Load & Save to val's in app.config file ?
for example: to save & to load Connection string
thank's in advance
|
|
|
|
|
1) to add in the xml:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="MyConfig" value="MyValue" />
</appSettings>
</configuration>
2) to load/read something like this:
string myConfig =
System.Configuration.ConfigurationSettings.AppSettings["MyConfig"];
|
|
|
|
|
Hello all,
I am trying to create a UserControl that has some Style properties, I am not sure how to get the Style or StyleCollection to show up correctly in the Designer. I can set
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
and it will display all the Style types without a group i.e. Style-BackColor, Style-BorderColor etc. But when I set
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
the Style property does not show up at all. If anyone knows of a good article on this that would be a great help also.
Thanks!
-Andy
|
|
|
|
|
i want code for a program:
i want to enter a number in between 4000 and 8000.also that entered number must contain a digit 2.otherwise it show invalid. eg:4002,4012,5222.
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:47am.
|
|
|
|
|
thanks for your kind reply.
I am a fresher in this field..
Can u please give me a detailed explanation?
Then it will be very helpful to me...
|
|
|
|
|
And I want money
Anyway here's one way to do it:
1)Check if number is between 4000 and 8000
2) If so then check if it contains a "2". Something like this:
string nr = yourNumbert.ToString();
if(nr.Contains("2")){//do stuff
else{//complain about it
|
|
|
|
|
thanks for your kind reply.
I am a fresher in this field..
Can u please give me a detailed explanation?
Then it will be very helpful to me.....
|
|
|
|
|
thanks for your kind reply.
I am a fresher in this field..
Can u please give me a detailed explanation?
Then it will be very helpful to me...
|
|
|
|
|
thanks for your kind reply.
I am a fresher in this field..
Can u please give me a detailed explanation?
Then it will be very helpful to me....
|
|
|
|
|
It's getting Exam Time Again... Bram van Kampen
|
|
|
|
|
Unfortunately, I'll have to work hard and save up.
|
|
|
|
|
Good Morning,
When my application opens, it checks a version number from an online database to determine if it is using the most current version available. If not, I need it to be able to download the most current version from an online server and then install the application update automatically. I know we see examples of this every day, such as security updates in Windows or online checks for anti-virus programs. The check and automatically close if not installed are already working fine and return a Boolean. How do I force and install the download?
Thank You, Pat
|
|
|
|
|
|
Thank for your answer. I have marked it as correct for this issue. I was able to use it to get the string of code that I needed to resolve the download problem. Now, I need to be able to find a way to automatically install the download. Best Regards, Pat
|
|
|
|
|
Hi all,
I have a NOOB question, when developing a custom user control how can you reference other classes or use a partial class? For some reason when I try to reference another class it can not find it. I tried using the same namespace in the separate class file and tried putting it in the bin directory without any luck. Thanks for the Help!
-Andy
|
|
|
|
|
If the class is in another assembly you must remember to add a reference before it will be available.
Perhaps if you showed a bit of the code we could evaluate it. And don't forget to format the code using the pre tags. I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks Mark, I was hoping it was something simple, sometimes the easiest things give you the most problems, here is a layout of my code....
myControls.ascx.cs:
namespace myControls
{
public partial class MyUserControl : System.Web.UI.UserControl
{
public MyEnum myEnum;
protected void Page_Load(object sender, EventArgs e)
{
(.......)
}
}
}
myControls.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="myControls.ascx.cs" Inherits="myControls.MyUserControl" %>
<div>
</div>
myControls.Support.cs
namespace myControls
{
public enum MyEnum
{
Day,
Week,
Month,
}
} Thanks again,
Andy
|
|
|
|
|
You need to include the namespace of that class in your project (if it is under a different namespace).
For e.g.
using System;<br />
using System.input;<br />
using myNamespace;
OR
alternately you could just try
new myNamespace.myClass() .Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
Abhinav,
I tried referencing the namespace but the main problem is the User Control can not find the separate class file. Everything works right when I include the Enum in the same file but when I try to use it it gives me errors that it can not find the assembly or reference.
Thanks
Andy
|
|
|
|
|
I saw your code (pasted above).
See a note here[^].
"The partial modifier is not available on delegate or enumeration declarations."Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
modified on Wednesday, February 10, 2010 10:09 AM
|
|
|
|