|
Hi,
maybe what you need is File.CreateText() and XmlDocument.Save(TextWriter) ?
check the doc!
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi,
I am implementing a mechanism that check a user is logged in before showing the aspx pages.
I have tried to implement this in the code behind of the master page of the restricted pages.
In case there is no-one logged in the page must redirect to the appropriate "No-Rights" page.
The problem is that the master page can be used by pages at different folder levels. How to redirect the response to the correct URL of the page? How to specify the URL relative from the web-application root?
Another typical problem here is that when debugging using Visual Studio, the pages are relative to the localhost/PROJECT-NAME/pages. But when deployed the pages are placed directly under HOST/pages.
Can anyone help?
Thanks,
Colin
|
|
|
|
|
First of all this should have been posted in the ASP.NET Boards[^].
From what I recall, you are going to have to use ~ to go to the root of the directory.
i.e.
localhost/Project-Name/Restricted/test.aspx
=
~/Restricted/test.aspx
so even if you were on localhost/Project-Name/Restricted/test.aspx you could reference to the login page with something like this (assuming your login page is in the root of the website), ~/login.aspx
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Good afternoon I am trying to populate a DataGridView, but for some reason when I click the Query button the grid remains blank. I know the query works. My code is as follows:
Form
private void btnQuery_Click(object sender, EventArgs e)
{
PwdSecurity p = new PwdSecurity();
uipc = this.Parent as UIPCMainForm;
const string constrallowedBlockTypes = "allowedBlockTypes";
DAL d = new DAL(uipc.StrUserName, p.base64Decode(uipc.StrPassword));
dgv.DataSource = null;
dgv.Refresh();
bs = new BindingSource();
bs.DataSource = d.AllowedTypes(constrallowedBlockTypes);
dgv.ScrollBars = ScrollBars.Both;
dgv.DataSource = bs;
}
private void btnUpdate_Click(object sender, EventArgs e)
{
dgv.Update();
}
DAL
public DataSet AllowedTypes(string Type)
{
string SQL = String.Empty;
ds = new DataSet();
try
{
SqlCmd = new SqlCommand("spGET_ALLOWED_TYPE", myConnection);
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlCmd.Parameters.Add("@Type", SqlDbType.VarChar, 50);
SqlCmd.Parameters["@Type"].Value = Type;
if (myConnection != null) { myConnection.Close(); }
myConnection.Open();
SqlAdapt = new SqlDataAdapter(SqlCmd);
SqlAdapt.Fill(ds);
}
catch (Exception e)
{
MessageBox.Show("DAL Layer / AllowedTypes method error. \n\r \n\r" +
e.Message.ToString() + " \n\r \n\r" + SQL);
}
finally
{
if (myConnection != null) { myConnection.Close(); }
if (SqlCmd != null) { SqlCmd.Dispose(); }
if (SqlAdapt != null) { SqlAdapt.Dispose(); }
}
return ds;
}
I don't use DataGridView much, but I was wondering if I neglected to create the columns or something. I confirmed the dataset being returned full of data.
Also I am trying update the information on the table if a user changes it on the DataGridView (see btnUpdate event).
Thank you, WHEELS
|
|
|
|
|
Try This[^]
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Good afternoon.
Although I am getting closer, I can't seem to get the DataGridView to populate with the dataset.
private void btnQuery_Click_1(object sender, EventArgs e)
{
PwdSecurity p = new PwdSecurity();
uipc = this.Parent as UIPCMainForm;
const string constrallowedBlockTypes = "allowedBlockTypes";
DAL d = new DAL(uipc.StrUserName, p.base64Decode(uipc.StrPassword));
DataSet ds = new DataSet();
ds = d.AllowedTypes(constrallowedBlockTypes);
dgv.DataSource = null;
dgv.Refresh();
dgv.Columns.Add("ID", "ID");
dgv.Columns.Add("VAL", "VAL");
DataTable dt = new DataTable();
bs = new BindingSource();
bs.DataSource = ds;
foreach (DataGridViewRow dr in dgv.Rows)
{
dgv.Rows.Add(dt);
}
dgv.ScrollBars = ScrollBars.Both;
dgv.DataSource = bs;
}
What am I missing? Thank you, WHEELS
|
|
|
|
|
Given a window handle (IWin32Window), it is possible to get a "screenshot" of what this window currently looks like?
For example, if I have a form that is in some error state, I'd normally call some generic error handler function to display a message and/or log it...this function could be provided with the window handle of the caller...and I'd like this function to take a "screenshot" of the window that made the call, wired up in such a way that anybody could call it in some generic fashion.
I must admit I haven't yet fully thought this through...does this even make sense?
(or, I suppose I could use a Form parameter instead of an IWin32Window, if it would make things easier...)
|
|
|
|
|
I haven't done this just using a window handle. However, if you can access the form object itself you can do something like this:
public void GetFormImage(Form frmIn, String ImagePath)
{
Bitmap bmpFormBackGround = new Bitmap(frmIn.Width, frmIn.Height);
frmIn.DrawToBitmap(bmpFormBackGround, new Rectangle(0, 0, frmIn.Width, frmIn.Height));
bmpFormBackGround.Save(ImagePath);
}
Hope it helps.
|
|
|
|
|
Thanks pelnor...that should go a long way.
|
|
|
|
|
I am relatively new to C# windows programming and have lots to learn. I want to call a function in a child window from the parent window in an MDI application. If I make the function STATIC the parent form can see it, however a control(textbox)in the child function is not recognized, 'MainWindow.FileForm.textBox1' denotes a 'field' where a 'class' was expected'. If I make the function non-static I cannot call it from the parent form. How do I accomplish the call? Thank you..
|
|
|
|
|
You do indeed have lots to learn, and this bit is fundamental.
When you declare a class, it does not exist yet:
public class Car
{
public static int GetWheels()
{
return 4;
}
public int GetFuel()
{
return fuel;
}
}
You can happily count the wheels, because that is common to all cars - they all have the same number of wheels.
...
Console.WriteLine("All cars have {0} wheels", Car.GetWheels());
...
But if you try to get the fuel, the compiler complains that you "need an instance". What it is saying is that a car could be diesel, petrol, or electric. GetFuel() cannot be static, because it is not shared by all cars. You can however refer to instances of cars:
...
Car myCar = new Car("Mitsubishi", "Diesel");
Car yourCar = new Car("Ford", "Petrol");
Car hisCar = new Car("Toyota", "Hybrid");
...
and then it is fine to refer to the specific car and it's fuel type:
Console.WriteLine("Your car is {0}", yourCar.GetFuel());
Console.WriteLine("My car is {0}", myCar.GetFuel());
Console.WriteLine("His car has {0} wheels", hisCar.GetWheels());
Does that make sense?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I like OriginalGriff's analogy!
Just in case it's not clear, and without the car thing...
Somewhere in your parent you are creating an instance of FileForm. Maybe something like this:
FileForm fileForm = new FileForm(); The instance fileForm is what you need to access that instance. If you need to, you can use the Parent's MdiChildren property to iterate over all child windows and find the instance you need.
foreach (Form form in MdiChildren)
{
if (form is FileForm)
{
FileForm fileForm = form as FileForm;
fileForm.YourMethod();
break;
}
} I notice you are trying to access FileForm.textBox1 . Control instances in a form are by default added as private and should stay that way. If you want to do something with a control, add a method or property in the FileForm class and use that to manipulate the control.
public void SetTextBox1(string text)
{
textBox1.Text = text;
}
fileForm.SetTextBox1("Hello World!");
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thank for taking the time to answer. Your suggestions worked! I mistakingly thought that instantiating the FileForm in the parent form would make FileForm labeled "FileWindow" visible.
FileForm FileWindow=new FileForm();
FileWindow.MdiParent=this;
FileWindow.Show();
As I'm an engineer an not a professional programmer I will never learn everything necessary to be competent. Just enough to solve a problem. If there are any books or references that you may know of that focus on applications and you have the time would you please respond.
Regards,
Bill C.
|
|
|
|
|
alias bill wrote: I will never learn everything necessary to be competent
Don't sell yourself short! C# isn't *that* hard. I don't know everything by a long way and still ask questions here myself from time to time, but I consider myself competent.
I don't have any C# books, so I can't recommend any personally. All my knowledge has been gained from studying articles/blogs/MSDN - and with the help of CodeProject, I've learned enough to know when what I am reading is rubbish or is good stuff.
Just keep at it, and with an internet connection you have all you need, though a good book will help if you can find any recommendations.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
i don know what kind of design you have in mind for your application
you can also use usercontrols like pages
create a single form that you fill with the usercontrols designed like page, then bring to front the page you want.
You can do this insead of creating child forms, if you don´t want to open new windows and run all the show in the same window
you have to manage delegates here
nelsonpaixao@yahoo.com.br
trying to help & get help
modified on Thursday, August 6, 2009 8:05 PM
|
|
|
|
|
Hello,
I am trying to use a Session Variable in an update command and the error that I continue to get is:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Server tags cannot contain <%...%>constructs.
It also says that the Datasource is not well formed when I try to enter it in. Could someone help me figure out how to use this?
The session variable I am trying to bring over is a global temp table name. Below is the code.
<asp:SqlDataSource ID="FAR15DataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:Cost_ModelConnectionString %>"
SelectCommand="SELECT Service_Tower_Code, WBS_Code, Ownertype, Compensation_Code, Compensation_Rate, Far_East_FTE, Hawaii_FTE,Mid_Atlantic_FTE, NCR_FTE, North_Midwest_FTE, Northeast_FTE, South_FTE, Southwest_FTE
FROM fn_enterprise_positions(1)"
UpdateCommand="UPDATE <%=Session["TableName"]%> SET Far_East_FTE = @Far_East_FTE, Hawaii_FTE = @Hawaii_FTE, Mid_Atlantic_FTE = @Mid_Atlantic_FTE, NCR_FTE = @NCR_FTE, North_Midwest_FTE = @North_Midwest_FTE, Northeast_FTE = @Northeast_FTE, South_FTE = @South_FTE, Southwest_FTE = @Southwest_FTE
WHERE Service_Tower_Code = @Service_Tower_Code AND WBS_Code = @WBS_Code AND Compensation_Code = @Compensation_Code AND worker_code = @worker_code">
<UpdateParameters>
<asp:FormParameter Name="Service_Tower_Code" FormField="Service_Tower_Code" />
<asp:FormParameter Name="WBS_Code" FormField="WBS_Code" />
<asp:FormParameter Name="Compensation_Code" FormField="Compensation_Code" />
<asp:FormParameter Name="worker_code" FormField="worker_code" />
<asp:FormParameter Name="Compensation_Rate" FormField="Compensation_Rate" />
<asp:FormParameter Name="Far_East_FTE" FormField="Far_East_FTE" />
<asp:FormParameter Name="Hawaii_FTE" FormField="Hawaii_FTE" />
<asp:FormParameter Name="Mid_Atlantic_FTE" FormField="Mid_Atlantic_FTE" />
<asp:FormParameter Name="NCR_FTE" FormField="NCR_FTE" />
<asp:FormParameter Name="North_Midwest_FTE" FormField="North_Midwest_FTE" />
<asp:FormParameter Name="Northeast_FTE" FormField="Northeast_FTE" />
<asp:FormParameter Name="South_FTE" FormField="South_FTE" />
<asp:FormParameter Name="Southwest_FTE" FormField="Southwest_FTE" />
</UpdateParameters>
</asp:SqlDataSource>
I did originally have a <asp:SessionParameter Name="TableName" /> inside the update parameters but that didnt seem to do anything. Thanks for your help!
John Michael
|
|
|
|
|
This is C# Forum. Please post it on ASP.NET Forum
|
|
|
|
|
Hi,
I have been trying to populate a table in word from C#, originally i was using this code which i found on an article on this site and just adapted:
public void CreateFileColumn(ArrayList array, Array Numbe)<br />
{<br />
object missing = System.Reflection.Missing.Value;<br />
object fileName = "normal.dot";<br />
object newTemplate = false;<br />
object docType = 0;<br />
object isVisible = true;<br />
Object oUnit = Word.WdUnits.wdCell;<br />
<br />
<br />
wordApp = new Word.ApplicationClass();<br />
wordDoc = wordApp.Documents.Add(ref fileName, ref newTemplate, ref docType, ref isVisible);<br />
wordApp.Visible = true;<br />
wordDoc.Activate();<br />
<br />
wordApp.Selection.Tables.Add(wordApp.Selection.Range, 1, 8, ref missing, ref missing);<br />
<br />
wordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;<br />
wordApp.Selection.Font.Bold = (int)Word.WdConstants.wdToggle;<br />
<br />
<br />
foreach (string part in Numbe)<br />
{<br />
wordApp.Selection.InlineShapes.AddPicture(@"C:\Users\Jon\Documents\Nick\Chin Font Files\" + part + ".jpg", ref missing, ref missing, ref missing);<br />
wordApp.Selection.MoveRight(ref oUnit, ref missing, ref missing);<br />
}<br />
<br />
<br />
<br />
<br />
}
all this does is take an image from the folder listed and place them in a cell in the table, and keeps doing this until the arraylist is empty. However, it has got to the point now where i need to be more precise then just move right, i need to select which table i am in and what cell i am placing the image in. I know there is ways using cell[] and table[], but i don't know how to implement this in this piece of code.
Any help would be greatly appreciated
|
|
|
|
|
try using this
Word.Range rngC
rngC = YourTableName.Cell(i, j).Range
rngC.InlineShapes.AddPicture(with all the params you need)
i = column
j = row;
|
|
|
|
|
how do i know/tell what the table name is?
thanks for your help so far.
|
|
|
|
|
i'll paste you some of my code and hope it will help you
public void insertTable(Word.Document oDoc, int nr, int nrMoment)
{
strct.bla ++;
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc";
Word.Table oTable;
Word.Table oTable1;
Object style = "Table Grid v2";
Word.Range rngC;
Object defaultTableBehavior = Type.Missing;
Object autoFitBehavior = Type.Missing;
object rng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
object oPageBreak = Word.WdBreakType.wdPageBreak;
Word.Paragraph oPara = oDoc.Paragraphs.Add(ref rng);
oPara.Range.InsertBreak(ref oPageBreak);
oPara.Range.Font.Bold = 1;
oPara.Range.Font.Size = 14;
oPara.Range.Font.Name = "Book Antiqua";
oPara.Range.set_Style(ref styleHeading2);
oPara.Range.Text ="M" + strct.nr[1].ToString() +" "+ strct.titluCadru[strct.bla].ToString();
oPara.Range.InsertParagraphAfter();
Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oTable = oDoc.Tables.Add(wrdRng, 1, 1, ref defaultTableBehavior, ref autoFitBehavior);
oTable.set_Style(ref style);
oTable.ApplyStyleLastColumn = false;
oTable.Range.ParagraphFormat.SpaceAfter = 5;
rngC = oTable.Cell(1, 1).Range;
rngC.Font.Name = "Book Antiqua";
rngC.Font.Bold = 0;
rngC.Text = "Obiectivele educaţionale acoperite de moment, submoment şi itemul de învăţare \r\n Obiective operaţionale";
rngC.ParagraphFormat.SpaceAfter = 3;
rng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
Word.Paragraph oPara1;
oPara1 = oDoc.Paragraphs.Add(ref rng);
oPara1.Range.Font.Bold = 1;
oPara1.Range.Font.Name = "Book Antiqua";
oPara1.Range.Text = "O1";
oPara1.Format.SpaceAfter = 2;
wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oTable1 = oDoc.Tables.Add(wrdRng, nr + 11, 2, ref defaultTableBehavior, ref autoFitBehavior);
oTable1.set_Style(ref style);
oTable1.ApplyStyleLastColumn = false;
oTable1.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oTable1.Range.ParagraphFormat.SpaceAfter = 6;
rngC = oTable1.Cell(1, 1).Range;
rngC.Font.Bold = 1;
rngC.Font.Name = "Book Antiqua";
rngC.Text = "Descriere";
}
}
to use a certain table you can use a bookmark, create it from scratch, or put it in an array (haven't used this last one). Hope this helps
|
|
|
|
|
Sorry if i seem a bit thick, could you paste an example of how to call that routine, what would you place in the first argument? This is all rather new to me.
|
|
|
|
|
Can someone help with an issue I'm having with a CheckListBox.
I have two Forms lets say Form1 - Form2, Form2 contains a CheckListBox that accepts input from the user I've also created a Foreach statement to Iterate through the CheckListBox on Form2 Form1 has a button coded to call Form2 Foreach method everything seems to work except for one problem when making the call to Form2 the Foreach method indicates the CheckListBox is Null although the CheckListbox contains item's, so as a test I created a button on Form2 and wired it to call the Foreach method on Form2 and all works the Foreach Method see's the Item's and perform the Iteration on all Item's where as making the call from Form1 indicate a Null CheckListBox. I'm not sure if this is a Threading issue do to the fact Form1 is creating a new Object to access Form2 Foreach method ?
FORM1
button1_Click(object sender, EventArgs e)
{
List.Form2 List = new List.From2();
List.ChkList();
}
FORM 2
Public void ChkList()
foreach (string s in checkedListBox1.Items)
{
if (s.Equals(dt))
{ Do Work
}
FORM2 Test Button.
button2_Click(object sender, EventArgs e)
{
List.Form2 List = new List.From2();
List.ChkList();
}
|
|
|
|
|
Works without a problem on my system using the setup you described. It shouldn't be a threading issue based on what you said. It more than likely is an ordering issue of when the items in the list get populated. If you populate them on Load (only called when the Form is shown) or via some other event, those won't be called on construction. So, you might want to start there. Just place breakpoints around the sections that load data into that list and go from there.
|
|
|
|
|
the situation is completely unclear.
is it From2 or Form2?
is the "List" form shown at all, I see no List.Show()?
where is the declaration of checkedListBox1? and its assignment?
etc etc
and how could it be a threading issue, you haven't shown anything related to threads?
BTW: your button2_Click() method probably proves nothing as it (1) only can work after its Form is fully loaded and shown, (2) creates yet another "From2", and (3) is located inside Form2 class, so it is completely different from what button1_click() is doing.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|