|
For the offical word on CAPICOM support under Windows 7, read this[^].
After about 90 minutes of excersizing my Google Fu, I finally found this[^], which states that I'll have to resort to P/Invoking the Win32 functions I need to get the files signed with an embedded signature. Yuk! Why couldn't they provide an entirely managed solution to replace CAPICOM?!
|
|
|
|
|
Hi,
I need to write a program which can copy a file simply from a source folder to a destination folder.
Please include the codes for a simple program doing so.
|
|
|
|
|
Below is the sample VB.NET Code. Hope you can convert it easily using C#.
using System.IO
Public Sub CopyDir(ByVal strSrc As String, ByVal strDest As String)
Dim dirInfo As New DirectoryInfo(strSrc)
Dim fsInfo As FileSystemInfo
If Not Directory.Exists(strDest) Then
Directory.CreateDirectory(strDest)
End If
For Each fsInfo In dirInfo.GetFileSystemInfos
Dim strDestFileName As String = Path.Combine(strDest, fsInfo.Name)
If TypeOf fsInfo Is FileInfo Then
File.Copy(fsInfo.FullName, strDestFileName, True)
'This will overwrite files that already exist
Else
CopyDir(fsInfo.FullName, strDestFileName)
End If
Next
End Sub
Source : http://abhijitjana.blogspot.com/2007/10/copy-files-from-one-directory-to.html[^]
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
If you keep writing their code for them the will pass the exams, and one day you may end you having to mantain some of their code - even worse, I may end up having to fix it
Give a hint, but please refrain from giving code for something as trivial as this otherwise they will never learn that one of the more important aspects of development is learning how to work things out for yourself. I mean, how difficult is it to go to google and put in file copy c# and look at the top few of the 815,000 hits.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Ashfield wrote: Give a hint,
Most of the cases I did the same. Just give the hint so that they can take it forward.
Ashfield wrote: how difficult is it to go to google and put in file copy c# and look at the top few of the 815,000 hits.
I do the same and Got the link from my Old Blog and I put it over here.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
use
System.IO.File.Copy(src,dest)
where src and dest are source and target respectively.
|
|
|
|
|
If I were to invent a company policy about when programmers should or shouldn't override the Equals() function, what should that policy be and why?
I know when to do it on a case by case basis, but how would I establish a that in terms of a company policy or coding standards document?
Your thoughts?
|
|
|
|
|
When (not) to override Equals()[^].
Don't know if this actually helps you but I found it a couple of days ago.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Whenever a reference type's equality should be determined by something else (such as a field/property's value or reference) rather than the class' reference itself.
|
|
|
|
|
sory thet my english in is not good
i need to convert class i build to byte [] array,
for send it over socket .
after i received the byte i wona convert it again to my class
thenk for help
bar !
my class :
namespace WindowsFormsApplication1
{
public class Class1
{
private string a;
public Class1()
{ }
public Class1(string a)
{ this.a = a; }
public void set (string a)
{ this.a = a; }
public string get()
{ return this.a; }
}
}
|
|
|
|
|
|
who i can make it ?
you can send me a code?
tenks!
|
|
|
|
|
b.sahahf wrote: you can send me a code?
If you pay for it, yes. Otherwise, you'll have to write it yourself. The documentation is usually a good place to start, the link to the BinaryFormatter contains a sample that can almost be copied literally. It contains this sample;
static void Serialize()
{
Hashtable addresses = new Hashtable();
addresses.Add("Jeff", "123 Main Street, Redmond, WA 98052");
addresses.Add("Fred", "987 Pine Road, Phila., PA 19116");
addresses.Add("Mary", "PO Box 112233, Palo Alto, CA 94301");
FileStream fs = new FileStream("DataFile.dat", FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
try
{
formatter.Serialize(fs, addresses);
}
catch (SerializationException e)
{
Console.WriteLine("Failed to serialize. Reason: " + e.Message);
throw;
}
finally
{
fs.Close();
}
} Good luck with your project
I are Troll
|
|
|
|
|
|
I wrote a program that will find all links to PDF's on a site and download them. However when I look at the downloaded PDF's they are all the same size and corrupted. If I download them via IE they are differnt sizes and they open just fine.
My download code is:
Webclient wc = new WebClient();
wc.DownLoadFile("http://www.somesite.com/somepage/somefile.pdf", "c:\site\somefile.pdf");
I get no errors. I'm not sure if this makes a difference but if I look at the source of the site they have the href to the pdf as href="/somepage/somefile.pdf" I string the hostname to the front of the URL.
I know I can do an httpwebrequest but how will I know how big to make my buffer.
Suggestions?
Thanks
Tom Wright
tawright915@gmail.com
|
|
|
|
|
Have you ever looked what is in those corrupted PDFs? Maybe you will find a html-site that tells you that the file wasn't found on this server or you maybe haven't the right to access to file directly.
|
|
|
|
|
Your right....opened it with a hex editor and found HTML. Renamed the extension to .html and it's the logon page.
Okay so even though I have logged on outside of my app and checked the box to remember me, it does not use that cookie. So how do I pass the username and password in my app to grab the file?
Thanks
Tom Wright
tawright915@gmail.com
|
|
|
|
|
To access files from a website that saves the login in a cookie is hard.
You have to find the cookie the website saved on your computer and send it with the HTTP-Request Header.
(I don't know an other way except the website has a possibility to login per querystring (ex. data.aspx?user=abc&pwd=pwd)).
|
|
|
|
|
If I dumped the html in to a bowser object on my app where the end user logged on, would those credentials carry over to my app? Hope this makes sense.
Tom Wright
tawright915@gmail.com
|
|
|
|
|
I think those credentials will only work in the scope of your app browser object.
But you can download those pdfs if you get your browser object to do this for you.
(I have build an app like yours a time ago and had the same problem, but I managed my browser object
to do the steps (but not downloading) I wanted to automate.)
|
|
|
|
|
Hello gurus and mavens!
I haven't had to post any problems here in a while - which I take to be good sign for me. And this one isn't so much a "problem" as a "question".
I thought the compiler would choke on the following code:
namespace ConsoleApplication1
{
public class MyClass<G>
{
private G Val;
public MyClass(string initStr)
{
if (initStr == "bad init string")
throw new ApplicationException("You can't do that!");
Val = default(G);
}
public MyClass(G initVal)
{
Val = initVal;
}
}
class Program
{
static void Main(string[] args)
{
MyClass<int> example1 = new MyClass<int>("test");
MyClass<int> example2 = new MyClass<int>(1);
MyClass<string> example3 = new MyClass<string>("what happens here?");
}
}
} and tell me that it did not know which constructor to use with example3 since both constructors for MyClass would accept a string. But it didn't! Instead it just elects to use the constructor with the parameter of type string. Not what I expected, and not what I wanted.
To get around this, I changed the second constructor to
public MyClass(G initVal, bool dummy) and the call to
MyClass<string> example3 = new MyClass<string>("what happens here?", true); just to make it clear that I want to use the second constructor.
My question is this: is there a better way to handle this that I am not aware of? Is there some hidden option or obscure construct that makes sense of ambiguous constructor signatures?
Many thanks,
Clive Pottinger
Victoria, BC
|
|
|
|
|
This is expected behavior. MyClass(G) when G is a string becomes MyClass(string) . As a constructor with those parameter types already exists a new one is not generated by the compiler as the parameter list must be different to successfully overload.
|
|
|
|
|
I'd go further and say this is the desired behaviour for the generic overload (i.e. I think the .Net framework makes the correct choice). MyClass(string foo) is explicitly stating "I deal with strings" and is therefore concrete, whereas MyClass(G foo) is stating "I deal with 'G's" which is less concrete.
The design in the OP needs refactoring IMO, the concrete MyClass(string foo) ctor needs to be removed unless there is a specific reason for dealing with strings specifically. The validation performed on the strings is likely to be, but not necessarily, valid for other types.
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|
Thanks guys.
That explains why it acts like it does.
keefb wrote: The design in the OP needs refactoring [...] unless there is a specific reason for dealing with strings specifically.
In the actual code MyClass is a class that represents some kind of value. The first ctor (MyClass(string initStr) ) is used when the initStr holds a formula that needs to be parsed and evaluated to get the value. The second ctor (MyClass(G initVal, bool dummy) ) is used when the value is already known, and does not need to be parsed or evaluated. The confusion arose, of course, when the value is a known string.
I will take your recommendation to remove the first ctor into consideration, but at this point, I don't see a way for it work (is MyClass("foo()") a request for the string returned by foo or for the string "foo()"?). In the meantime, I will take it that my "workaround" is not wrong/dangerous/problematic/laughable.
Thanks again.
Clive Pottinger
Victoria, BC
|
|
|
|
|
Clive D. Pottinger wrote: The first ctor (MyClass(string initStr)) is used when the initStr holds a formula that needs to be parsed and evaluated to get the value
This is a worry*, and the source of your problem. If possible, you should defer the instantiation of this class until you have the value you want to use. If I understand you correctly, by passing the formula as a string will require the current class to be responsible for performing the parsing as well as whatever this class is meant to do with the result, this is probably bad object encapsulation.
A better way to handle this is to create an object which is responsible for the storage and parsing of the formula, and pass the results of the formula into the current class ,explained in your original post. This will separate the concerns more clearly.
* This is a worry because, unless you are parsing text entries from a user or some other source (e.g. text input from a UI or file), writing formulas in strings and then evaluating them is bad design (and a real pain. If this is the case, then it's unavoidable. If you are just using this to pass formulae around within the application, you should look at c# delegates(which allow you to pass methods around as parameters) and possibly the strategy pattern.
Hope this helps!
CCC solved so far: 2 (including a Hard One!)
|
|
|
|