|
Have you forgotten to close the DB connection when done, so the connection pool would get exhausted pretty soon?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Are you maing the HUGE mistake of opening a connection to the database in your app when it starts and never closing it until your app closes??
|
|
|
|
|
Hi All,
I want to change a folder permission, by default the folder has "Read" permission , I want to change it to both "Read" & "Write" permission. I tried to use sample programs in MSDN , but some how it is not working, I have attached my source code with this message, If there is any useful pointers to this problems kindly let me know, u r help will be much appriciated
using System;
using System.IO;
using System.Security.AccessControl;
namespace FileSystemExample
{
class DirectoryExample
{
public static void Main()
{
try
{
string DirectoryName = @"C:\Inetpub\ftproot";
Console.WriteLine("Adding access control entry for " + DirectoryName);
AddDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.Write, AccessControlType.Allow);
Console.WriteLine("Removing access control entry from " + DirectoryName);
RemoveDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.Write, AccessControlType.Allow);
Console.WriteLine("Done.");
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadLine();
}
public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
DirectoryInfo dInfo = new DirectoryInfo(FileName);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
Rights,
ControlType));
dInfo.SetAccessControl(dSecurity);
}
public static void RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
DirectoryInfo dInfo = new DirectoryInfo(FileName);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account,
Rights,
ControlType));
dInfo.SetAccessControl(dSecurity);
}
}
}
Mike
|
|
|
|
|
I want to have a class name Faculty with some memeber properties. One of the property is a (list of student classes) List<myStudent>. I have a student class (as given below).
When I compile I get the following error:
"Inconsistent accessibility: parameter type 'NestedClass.myStudent' is less accessible than method 'NestedClass.myFacultyMember.AddMyNewItem"
What am I doing wrong?
Cannot we access user defined data types (in this case a class object) within a class from outside?
Thank you in advance!
------------student class-----------------------
<using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NestedClass
{
class myStudent
{
private int studentID;
private string firstName;
private string lastName;
private int age;
public myStudent()
{
}
~myStudent()
{
}
public int StudentID
{
get
{
return studentID;
}
set
{
studentID = value;
}
}
public string FirstName
{
get
{
return firstName;
}
set
{
firstName = value;
}
}
public string LastName
{
get
{
return lastname;
}
set
{
lastname = value;
}
}
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
}
}
----------- Faculty Class ---------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NestedClass
{
public class myFacultyMember
{
private int facultyID;
private string firstName;
private string lastName;
private int age;
private List<myStudent> lst_Students = new List<myStudent>();
public myFacultyMember()
{
}
~myFacultyMember()
{
}
public int FacultyID
{
get
{
return facultyID;
}
set
{
facultyID = value;
}
}
public string FirstName
{
get
{
return firstName;
}
set
{
firstName = value;
}
}
public string LastName
{
get
{
return lastName;
}
set
{
lastName = value;
}
}
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
public void AddMyNewItem(myStudent newItem)
{
lst_Students.Add(newItem);
}
}
}>
|
|
|
|
|
myStudent class is private and myFacultyMember is public. You can't expose myStudent class as it is private. To resolve, make it public.
|
|
|
|
|
Hi,
I am trying to read the date from one file into another a new file.
(I know I could just copy it, but I will eventually be processing the data inbetween so I need to do it this way).
So first I create a StreamWriter with the existing path, then I create a StreamReader with the new path, and copy one to the other.
StreamWriter writer = new StreamWriter (existingFilePath);
StreamReader reader = new StreamReader(copiedFilePath);
string strData = reader.ReadToEnd();
Writer.Write(strData);
writer .Close();
reader.Close();
And the end result.... the new file is about 25mb but the old file was only 19mb.
Is this to do with the encoding? Its a PNG file I have selected but ultimatly it could be any file type.
I need to create an EXACT copy! Please help
James
|
|
|
|
|
jehazlam wrote: string strData = reader.ReadToEnd();
jehazlam wrote: PNG file
That is not a string. There is no encoding, it's just raw binary data.
You could use File.ReadAllBytes , for example
|
|
|
|
|
Better you copy the stream in chunks:
StreamWriter writer = new StreamWriter (existingFilePath);
StreamReader reader = new StreamReader(copiedFilePath);
byte[] buffer = new byte[32768];
while (true) {
int read = reader.Read (buffer, 0, buffer.Length);\
if (read <= 0)
break;
writer.Write (buffer, 0, read);
}
writer .Close();
reader.Close();
Best regards,
Jaime.
modified on Monday, October 12, 2009 12:41 PM
|
|
|
|
|
Would this be better?
while (reader.Read (buffer, 0, buffer.Length) > 0 ) {
writer.Write (buffer, 0, read);
}
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
where is the 'read' variable filled?
Best regards,
Jaime.
|
|
|
|
|
It isn't and does not need to be unless you want to compare the number of bytes read with size of buffer. In which case you could do something like:
int read = 0;
while ((read = reader.Read (buffer, 0, buffer.Length)) > 0 ) {
writer.Write (buffer, 0, read);
}
if (read < buffer.Length) {
}
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
riced wrote: It isn't and does not need to be unless you want to compare the number of bytes read with size of buffer
Well, it is always necessary, because on last read, the buffer is partially filled, so the last write is not full buffer contents.
Best regards,
Jaime.
|
|
|
|
|
.
modified 2-Apr-21 5:17am.
|
|
|
|
|
What on earth are you doing ? Creating dlls from resources ? How bizarre. Why create one at c:\ ? Perhaps if you showed us the actual code and told us the actual error message, we could help more ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
|
Add your directory name to the environment PATH variable. Windows searches these directories to find referenced dll files.
|
|
|
|
|
|
Yes, it would seem my brain saw the word 'dll' and immediately thought 'C/C++', whereas the actual forum is C#. I'll check these links out for future reference; thanks.
|
|
|
|
|
|
Hi
I think that you are searching for the Assembly.Load method that load an assembly for dynamic invocation.
|
|
|
|
|
Given that you're creating them yourself, why not just put them in the right place ? c:\ is a RETARDED place to put dlls for your program.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
hi,
if this dll is a com-dll you can register the dll with regsvr32 "C:\your_com.dll".
To use the dll you need to declare the function like win32api in dotnet with a DllImport()..
if the dll is a .net assembly load the dll with System.Reflection.Assembly.LoadFile().
don't know what you want to do or your program.. if you dont want to write code using the dlls try to reinstall your programm using the dlls
greetings
|
|
|
|
|
Hello, all!
First, there is an integer array for example 1,2,3,4
Second, there are logical "rules" of following types: 1&2 = rule_1, 1|3 = rule_2, 1^4 = rule_3
(& - AND, | - OR, ^ = NOT)
The task is to search for the rules. So the question is how can I implement this kind of search, are there any source codes or libraries? I'll be very glad if someone helps me to cope with this problem and offers some ideas or examples especially on C#. Beforehand, great thanks!
|
|
|
|
|
Your question is unclear hence no replies.
You might want to try rewording it.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
I have an arrray of simple rules ID (int), my task is to search complex rules, containing simple rules that are united with each other by logical operators such as OR, AND, NOT. For, example, I have a complex rule 1 AND 2 NOT 3. There are simple rules IDs 1,2,4. If you search complex rules you will find complex rule (1 AND 2 NOT 3). So is it clear for you now, if not try to explain what you don't understand. Thanks.
|
|
|
|