|
cidmi.dovic wrote: I try to open the file I have always the message that the process can't acces the file because it is being used by other application
Can you please post the code used, here ?
Found my answer helpful? Then vote for it. "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
FileInfo file = new FileInfo(ConfigurationSettings.AppSettings["FilePath"]);
using (FileStream fStream = file.OpenRead())
{
}
|
|
|
|
|
Try this:
FileInfo file = new FileInfo(ConfigurationSettings.AppSettings["FilePath"]);
using (FileStream fStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
{
}
|
|
|
|
|
Yes, it works.
A lot of thanks!!!
|
|
|
|
|
If someone answers your question, vote their answer so the rest of us don't waste time trying to give you the same answer.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Well, I'll try to copy the file and open this new file.
|
|
|
|
|
The other application that's writing to the file may have set the sharing to None, meaning no other app can open the file for any reason as long as the first app has it open.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
hi all..
i have a problem as u can guess...i have two forms..in Form1 i have a datagridview and it gets datas from my database..i added datas to database from Form2 everything is ok till here but when i added data and closed the Form2 then i cant see the new row in my datagridview...i want to see new row when i finished my adding...to see the new row i used the codes Form2 closedevent
Form1 frm1=new Form1();
frm1.datagridview1.Refresh();
but still i cant see the new row that i have just added..what can i do to see it ??
|
|
|
|
|
try this:
in form1:
form2 f2=new form2();
f2.showdialog();
frm1.datagridview1.Refresh();
|
|
|
|
|
hi man
thanks for the reply...so which event i will write that code??
i used it in Form1_Load but it didnt work and directly my Form2 was opened not Form1
do u have any other suggestion ?
|
|
|
|
|
create button1
and put it in button1_Click(....)
|
|
|
|
|
i used that codes in the button that i use it to open Form2
but still i didnt get the result i wished...and i used the same codes in the button tht i have Form2 that i use it to close Form2 but it didnt work also
|
|
|
|
|
try this:
in form1:
form2 f2=new form2();
f2.showdialog();
frm1_load(...);<<<<<<<<<<<<<<<<<<<<
|
|
|
|
|
Not a good idea - it ties the design of form1 to the design of form2. I.e. if you replace the datagrid view in form1 with some other construct then it needs changes to form2 as well. This defeats one of the aims of an OOP language.
A better approach is to create an event in form2 which you subscribe to in form1. Then form2 internally needs to know nothing about who is using the data, it just signals "my data has changed" and all forms that subscribe to the event then update themselves appropriately.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Hello,
for solving you're problem, you can use delegates.
Take a look here.
Cheer's,
Alex Manolescu.
|
|
|
|
|
so how i can use delegates here ??
i mean which parameter i can send to the method ??
i will be happy if u help me about it ?
|
|
|
|
|
hi,
I've made a small project for you.
Supose you have a DataGridView control with 1 column.
The value we need to pass to the AddRow method is the string info.
Form1:
- contains: a DataGridView and a Button
public partial class Form1 : Form
{
public delegate void InsertIntoDGV(string info);
public static InsertIntoDGV idv;
public Form1()
{
InitializeComponent();
idv = new InsertIntoDGV(AddRow);
}
public void AddRow(string info)
{
dataGridView1.Rows.Add(new object[] { info });
}
private void button1_Click(object sender, EventArgs e)
{
new Form2().ShowDialog();
}
}
And now Form2:
- contains a TextBox and a Button.
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1.idv(textBox1.Text);
}
}
Hope this helps!
Cheer's,
Alex Manolescu.
|
|
|
|
|
Did it solved you're problem man?
At least answer if you post a problem!
|
|
|
|
|
Dear Expert I have usercontrol to create a new record/edit an existing record. The usercontrol have two constructors. one for "Create new record " and other for Load existing record for edit. When page have id in query string then load existing record for edit constructor execute otherwise create new rocord constructor executes.
The following is the code behind of usercontrol ("ContractControl")
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DynamicForms.Portal.Controls
{
public partial class ContractControl : System.Web.UI.UserControl, IContract
{
protected bool _createMode;
public ContractControl()
{
_createMode = true;
this.Save += new EventHandler(ContractControl_Save);
this.Cancel += new EventHandler(ContractControl_Cancel);
}
public ContractControl(IContract contract)
{
_createMode = false;
this.Save += new EventHandler(ContractControl_Save);
this.Cancel += new EventHandler(ContractControl_Cancel);
ID = contract.ID;
Client_ID = contract.Client_ID;
Name = contract.Name;
}
protected void Page_Load(object sender, EventArgs e)
{
}
#region IContract Members
public Guid ID
{
get
{
return Guid.NewGuid();
}
set
{
ID = value;
}
}
public string Name
{
get
{
return NameTextBox.Text;
}
set
{
try
{
NameTextBox.Text = value;
}
catch
{
}
}
}
#region Public Events
public event EventHandler Save;
public event EventHandler Cancel;
#endregion
#region Default Public Event handelrs
protected void ContractControl_Save(object sender, EventArgs e)
{
//Do Nothing
}
protected void ContractControl_Cancel(object sender, EventArgs e)
{
//Do Nothing
}
#endregion
protected void SaveButton_Click(object sender, EventArgs e)
{
Save(this, e);
}
protected void CancelButton_Click(object sender, EventArgs e)
{
Cancel(this, e);
}
}
Following code execute on pageload of my webpage where I used above usercontrol
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Params["id"] != null && Request.Params["id"].Length > 0)
{
Controllers.ContractController _controller=new Controllers.ContractController();
Controls.IContract _contract= _controller.Load(new Guid(Request["id"].ToString()));
ContractControl1 = new Controls.ContractControl(_contract);
}
else
{
ContractControl1 = new DynamicForms.Portal.Controls.ContractControl();
}
}
}
The new record is being created successfully. But editing throws following error
"An unhandled exception of type 'System.StackOverflowException' occurred in MyProject.web.DLL"
I am waiting your suggestions please.
|
|
|
|
|
Hi,
a StackOverflowException is always a hint that you produced an endless loop. I'm not able to see the problem in the code you posted, so I suggest you try to debug step-by-step.
Regards
Sebastian
|
|
|
|
|
UserControl is also inherited from IContract that I have passing to its constructor. Is this is making problem?
|
|
|
|
|
Maybe. Did you took look at the stack trace. Maybe the detail of the exception shows you where the problem is.
|
|
|
|
|
I have seen a database file that if you Attach it your self in SQL Server then the project that use that DB file will never runs anymore .
Alert :
If you attach that DB in Sql you can see all Tables , Views ,...
i am looking for that if someone attach my DB in SQL , my project never run on that system.
Alert :
I my self in project attach it.
modified on Monday, January 4, 2010 4:15 AM
|
|
|
|
|
Hallucinations? What is the question here? The hundreds of ways to make your database based application to not work. What are you actually looking for?
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
i am looking for that if someone attach my DB in SQL , my project never run on that system.
Alert :
I my self in project attach it.
|
|
|
|