|
Looks like readallbytes is about to become my friend, thanks for that I hadn't noticed it before.
Russell
|
|
|
|
|
Documentation promises an UnauthorizedAccessException for a read-only file
Luc Pattyn
|
|
|
|
|
Read only file is only one of the causes of that error.
The process might not have permissions to read the file for instance.
Russell
|
|
|
|
|
Sure, I am just saying
1) I dont understand why Read should fail on read-only files
2) you may have to read a read-only image file, for which File.ReadAllBytes would fail
Luc Pattyn
|
|
|
|
|
So I tried it on a read-only file, and it works.
I'm still puzzled why the doc mentions read-only as a possible cause for
UnAuthorizedAccessException.
It does not mention it for File.OpenText, OK
it does for File.OpenWrite, OK
it should not for File.ReadWhatsoever !
Luc Pattyn
|
|
|
|
|
I assume that the doc has been created by an automated process and 1 has been ammended later and the other not. The inconsistency with the other methods is bizarre but not unusual for MS.
Russell
|
|
|
|
|
Hi,
I need to transfer some data from one table to another in SQL Server 2000.
Here's the scenario:
Table 1 (Source): Name, Col1, Col2, Col3, Col4
Table 2 (Destination): Name, Cols
I want Cols to store the consolidated values of Col1 Col2 Col3 and Col4,
separated by 1 comma and a space, i.e. ,<space>
For example, if in Table 1, Col1 = 'Me' Col2='Myself' Col3='and' Col4='Irene'
Then in the Destination Table 2, Cols should be equal to 'Me, Myself, and, Irene'
This one is a real cracker. Will anyone be able work out a query or something?
If no one here can, I guess I can't go anywhere else.
Thanks.
ASP - AJAX is SEXY. PERIOD.
|
|
|
|
|
I do that into Microsoft Access 2000
I think it's work into SQL SERVER 2000
INSERT INTO Table2 ( name, cols )
SELECT Table1.name, [col1]+', '+[col2]+', '+[col3]+', '+[col4] AS Expr1
FROM Table1;
I hope that help you ...
|
|
|
|
|
Leaving aside my worries about DB normalisation as i assume this is being done for performance reasons.
INSERT INTO Table2 ( [name], cols )
SELECT Table1.[name], col1 & ", " & col2 & ", " & col3
FROM Table1
HTH
Russ
|
|
|
|
|
Thanks to both of you! Both methods work like a charm!!!!!
Yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa! Now I can uninstall
that stupid Toad util.
ASP - AJAX is SEXY. PERIOD.
|
|
|
|
|
Hello!
Ive got a Method1 with a try-catch. In Method1 I call Method2 which also has a try-catch. When exception is thrown in Method2, and the catch sequence is run, I want the application to end the current operation(not end the whole application, just what the user tried doing last). Instead the application keeps going in Method1 (where another exception soon will be thrown since Method2 wasn't run correctly). What is the best way of doing this?
/regards
|
|
|
|
|
You could rethrow the exception catched in Method2 or throw a new exception (preferrably using the catched one as inner exception), so Method1 is noticed something has gone wrong in Method2 and its try-catch gets immediatly entered.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Use the finally clause after the catch
|
|
|
|
|
|
welcome
|
|
|
|
|
i would return a success state from method2. If the exception that you caught in method2 could reasonably be described as expected (file does not exist, server not available etc) then i would not rethrow the error. If , however, the error is unexpected I would rethrow the Error adding the original error as the inner exception of the new exception object.
Let's say string method2 () is a load file method
If the user cancels the dialog or the file is not a text file and can't be read then instead of returning a string containing the text from the file i return a null. Method1 sees a null and exits without carrying out further work. If while trying to open the file an unrecoverable error occurs let's say a "Your Harddisk has borked" Error then I create and throw an exception and let the main app deal with it.
I'm a great believer in only throwing errors as a last resort and trying to not use them in the expected flow of an application.
Russell
|
|
|
|
|
If you catch the exception in Method2 and pretend that nothing is wrong, Method1 will be unaware of the error condition.
Re-throw the exception or throw a new exception in Method2, and handle that in the catch in Method1.
Alternatively (but this is sometimes frowned upon in object orientation) you can return a status from Method2 that tells Method1 if it succeeded or not.
---
Year happy = new Year(2007);
|
|
|
|
|
Hi All,
I am using a c#.NET windows application,
is there any explicit method for comparing two folders according to their size and date modified?
Send Me any Related Link.Please it's Urgent
thanks
Tirumal
|
|
|
|
|
AFAIK the only way is to compare folder contents, a file at a time.
Luc Pattyn
|
|
|
|
|
tirumal1231 wrote: .Please it's Urgent
It seems that it always is.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
To compare the date modified you can simply use DirectoryInfo.LastWriteTime . To compare the size I am afraid you have to recursively go through directories and their subdirectories and sum up FileInfo.Length of contained files.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
There is now Explicit Method but try this.
There may are some mistakes because i wrote it without much testing.
private long FolderSize = 0;<br />
<br />
private bool comparefolders(string path1, string path2)<br />
{<br />
string strdate_path1 = string.Empty;<br />
string strdate_path2 = string.Empty;<br />
long foldersize1 = 0;<br />
long foldersize2=0;<br />
bool folders_compare = false;<br />
try<br />
{<br />
DirectoryInfo dirinfo_path1 = new DirectoryInfo(path1);<br />
DirectoryInfo dirinfo_path2 = new DirectoryInfo(path2);<br />
if (dirinfo_path1.Exists == true && dirinfo_path2.Exists == true)<br />
{<br />
strdate_path1 = dirinfo_path1.CreationTime.ToString();<br />
strdate_path2 = dirinfo_path2.CreationTime.ToString();<br />
foldersize1 = GetFolderSize(path1);<br />
foldersize2 = GetFolderSize(path2);<br />
if (foldersize1 == foldersize2 && strdate_path1 == strdate_path2)<br />
{<br />
folders_compare = true;<br />
}<br />
}<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
string error = ex.Message;<br />
}<br />
return folders_compare;<br />
}<br />
<br />
private long GetFolderSize(string Root)<br />
{<br />
FolderSize = 0;<br />
SeekFiles(Root);<br />
return FolderSize;<br />
} <br />
<br />
private void SeekFiles(string Root)<br />
{<br />
string[] Files = System.IO.Directory.GetFiles(Root);<br />
string[] Folders = System.IO.Directory.GetDirectories(Root); <br />
FileInfo File;<br />
for(int i=0;i<Files.Length-1;i++)<br />
{<br />
File = new FileInfo(Files[i]);<br />
FolderSize += File.Length;<br />
}<br />
<br />
for(int i=0; i< Folders.Length-1; i++)<br />
{<br />
SeekFiles(Folders[i]);<br />
} <br />
}
-- modified at 4:26 Friday 19th January, 2007
|
|
|
|
|
sir this is aravind here ,,i cant able to run the program,,if u can able to send full program(A-Z),,i am new to Dotnet,,,,,plz
|
|
|
|
|
Well, there are some additional considerations here:
- if you add a new file in one of the subdirectories, it does not change the last write time
of the top directory
- if you delete a file and create another with equal size, it does not alter total size.
So be careful about when you are satisfied nothing happened to a directory !
BTW: I am not sure about this, but the exact behavior could also depend on the underlying
file system (FAT, FAT32, NTFS, ...)
Luc Pattyn
|
|
|
|
|
Thats right but he only wanted an method two compare the size and the modify date of the folder and not of the files in it.
|
|
|
|