|
Hi..
I'm trying to upload a image file to the server using HttpWebRequest/HttpWebResponse.
so i form a Postdata as and storing in a StringBuilder object (sbFormData)..
Content-Type: multipart/form-data; boundary=AaB03x
--AaB03x
Content-Disposition: form-data; name="submit-name"
Larry
--AaB03x
Content-Disposition: form-data; name="files"
Content-Type: multipart/mixed; boundary=BbC04y
--BbC04y
Content-Disposition: file; filename="file1.txt"
Content-Type: text/plain
... contents of file1.txt ...
--BbC04y
Content-Disposition: file; filename="file2.gif"
Content-Type: image/gif
Content-Transfer-Encoding: binary
...contents of file2.gif...
--BbC04y--
--AaB03x--
while adding the image content i read byte by byte and then adding to the sbFormData.
But when i see the sbFormdata's length its not showing exact length. That is not adding the image content's length.
Then setting the HttpWebRequest.Length to sbFormdata.Length..
httpWebRequest.ContentLength = sbFormData.Length;
after when i try to write the sbFormData to the httpWebRequest.GetRequestStream(), i get
Error:
"Bytes to be written to the stream exceed the Content-Length bytes size specified."
try
{
StreamWriter s = new StreamWriter(httpWebRequest.GetRequestStream());
s.Write(sbFormData.ToString());
s.Close();
}
catch (Exception e)
{
Debug.Print("Error in sending data " + e.Message);
}
Please help me..
regards,
nas
|
|
|
|
|
You are setting the content length to the number of characters in the string, but that is not the same as the number of bytes that the string uses when encoded. You have to encode the string first to get the size of the encoded data.
---
single minded; short sighted; long gone;
|
|
|
|
|
Thanx.. I got it..
|
|
|
|
|
Hi all,
I am having a application which i have to use a stored procedure to create it also the stored procedure requires two parameters (year and month is the criteria for the report).
please help me how to do this.i have a poor knowledge in Crystal reports please help me.
Regards
Ruwandi
rkherath
|
|
|
|
|
hi,
how to create an autoincrement id to be displayed on a textbox? the id will then be stored in the database table...
i have already created my code for that problem but it behaves differently.it behaves like this...if the current value of my pur_requestid in the table is null, then there would be no value displayed in the textbox. but if i inserted a value like 1 then when i execute my program the textbox receives 2.
i want my textbox to automatically display 1 eventhough i will NOT insert a value on my table.
my code that behaves differently...supposed to be the event being fired is when the user clicks the button NEW a purchase request id will be generated..
private void button7_Click(object sender, EventArgs e)
{
MySqlDataReader reader = null;
try
{
String query = "Select last_insert_id(pur_requestid) as lastinsertedid from purchaserequest where lpur_requestid = null order by pur_requestid desc limit 1";
MySqlCommand command = new MySqlCommand(query, connection);
reader = command.ExecuteReader();
if (reader.Read())
{
currentId = reader.GetInt64("lastinsertedid");
currentId = currentId + 1;
textBox1.Text = currentId.ToString();
}
}
catch (MySqlException mse)
{
MessageBox.Show(mse.Message);
}
finally
{
if (reader != null)
{
reader.Close();
}
}
thanks, hoping for your reply...
regards
-- modified at 22:59 Tuesday 8th May, 2007
jing
|
|
|
|
|
Hi,
I am binding a gridview to an objectdatasource
The gridview consist of columns and contains one CustomerId which is hidden (with datakeyname = "CustomerId")
In objectdatasource, here is the code
<asp:objectdatasource id="ObjectDataSource1" runat="server"
="" enablepaging="True" maximumrowsparametername="PageSize" selectmethod="AA_Paging_GetCountry" typename="admin" startrowindexparametername="StartRow" selectcountmethod="AA_Paging_GetRowsCount" oldvaluesparameterformatstring="original_{0}" conflictdetection="CompareAllValues" updatemethod="AA_Paging_UpdateCountry" onupdating="AA_Paging_OnUpdating" ondeleting="AA_Paging_OnDeleting" deletemethod="AA_Paging_Delete">
<deleteparameters>
<asp:parameter name="CountryId" type="Object">
So in my code behind:
public void AA_Paging_OnDeleting(Object source, ObjectDataSourceMethodEventArgs e)
{
if (selected == null)
{
//NEED ANSWER HERE TO ACCESS THE SELECTED DATAKEYNAME OR SELECTED CUSTOMERID TO FURTHER
//PROCESS THE LOGIC, AND IF IT LEADS TO CONDITION SO I CAN CANCEL THE DELETE OPERATION
//cancel delete operation
e.Cancel = true;
}
}
|
|
|
|
|
I have a simple xml file that displays a card file like in a Library. Each card has only one attribute, the index number. The cards are displayed in a treeview and when a use selects one I need to display the card's content in a window.
The problem is that I don't know how to access a single element by referencing the attribute "number".
Xml file:
<cardfile>
<card number="0">
<front>This is the front of card 1.</front>
<front>This is the back of card 1.</front>
</card>
<card number="1">
<front>This is the front of card 2.</front>
<front>This is the back of card 2.</front>
</card>
... etc.
</cardfile>
Thanks,
Mark
|
|
|
|
|
@ is the symbol used for attributes in an XPath. I think it's someting like "/cardfile/card[@number='0']"
The W3C website has excellent XPath tutorials on it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks for the help. I used SelectSingleNode with a path similar to the one you posted and it works fine. XPath seems to be as useful as RegEx!
Mark
|
|
|
|
|
It seems you are new to XML, so I don't suggest using low-level code, there is a easy to use System.Configuration namespace out there in MSDN Library, have a look at it.
1) Create a custom ConfigurationSectionGroup called cardfile
2) Create a custom ConfigutaionSection called card number
3) Create a custom ConfigurationElementCollection to store your front(s)
4) Create a custom ConfigurationElement called front
You can find all the source code examples for the steps 1->4 in MSDN library and in internet
This is the link:
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref4/html/T_System_Configuration_ConfigurationElement.htm
OR
Look for:
1) ConfigurationElemnt class in MSDN Library Index Tab filtered by Visual C#
2) Select "about ConfigurationElement class" and there you are
Hope this helps...
|
|
|
|
|
This doesn't throw any errors, but it also doesn't put the contents of my file into the textBox...
private void ReadFromFile(string[] filename)
{
TextReader tr = new StreamReader(openFileDialog1.FileName);
this.textBox1.Text = tr.ReadLine();
tr.Close();
}
Where am I going wrong?
|
|
|
|
|
try tr.ReadToEnd method please.
I think the first line is a blank string in your file.
|
|
|
|
|
When I saw your suggestion, I got excited. But, alas, there was no happy ending.
To put it in context, I'm including the openfiledialog as well.
private void openToolStripButton_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.openFileDialog1.InitialDirectory = @"c:\";
}
}
private void ReadFromFile(string filename)
{
TextReader tr = new System.IO.StreamReader(this.openFileDialog1.FileName);
this.textBox1.Text = tr.ReadToEnd();
tr.Close();
}
If you have any more suggestions, I'm all ears.
|
|
|
|
|
Soooo....where do you call ReadFromFile???
|
|
|
|
|
Oops, missed that. Thanks for the catch. Added it...now it just locks up.
By the way, did I say or do something wrong???
|
|
|
|
|
I sugguest you check the value of the openFileDialog1.FileName.Make sure that's a file's real path.
If this way cannot help you try these codes:
//First ,create a txt file at C:\
// create reader & open file
TextReader tr = new StreamReader(@"c:\1.txt");
// read a line of text
this.textBox1.Text = tr.ReadLine();
// close the stream
tr.Close();
Good luck.
|
|
|
|
|
If you're using .NET 2.0, System.IO.File.ReadAllText(openfileDialog1.FileName) should do it ( or something similar )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thank you so much. I love you , man...
|
|
|
|
|
I have a dataview..... When it retrieves data from the database there is a column in my data base that stores 1's and 2's. 1's mean 'Yes' and 2's mean 'No'. This column (St_Assess_Ev_Checked) has been declared as an Integer.
How do you iterate through a dataview, if it see's 1 it prints yes to my datagrid and if it see's 2 it prints no. This is my code so far.... hope I'm at least close.
DataSet sqlDS = new DataSet();
SqlDataAdapter sqlDA = new SqlDataAdapter(stReport, sqlConnection);
sqlDA.Fill(sqlDS, "progReport");
dv = sqlDS.Tables["progReport"].DefaultView;
IEnumerator iterator = dv.GetEnumerator();
foreach(DataRowView drv2 in dv)
{
for (int x = 0; x < dv.Count; x++)
{
if(dv[0]["St_Assess_Ev_Checked"].ToString() == "1")
{
dv.AllowEdit = true;
dv[0].BeginEdit();
dv[0]["St_Assess_Ev_Checked"] = "Yes";
dv[0].EndEdit();
}
else
{
Response.Write(dv[x].ToString());
}
}
}
You could of guessed the error.... Cannot convert types expected Int32!
Thanks in advance, appeciate it!
|
|
|
|
|
Do it in your datagrid ItemDataBound event. This should help you.
SG
|
|
|
|
|
Hi,
My English is not native, sorry.
I have MDI form and Child form.
I added "Form_Closing" event to the MDI code file. the following is the code:
private void frmMainMdi_FormClosing(object sender, FormClosingEventArgs e)
{
// Hold the MessageBox button pressed
DialogResult diaResult;
// Show Message to the User
diaResult = MessageBox.Show("Are you sure you want to cancel the setup?",
"Exit Setup",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button2);
// Checking which button as been pressed
if (diaResult == DialogResult.No)
{
// CANCEL pressed, set focus to the program
e.Cancel = true;
}
else
{
// YES pressed, exit the program
this.Dispose();
Application.Exit();
}
}
Now, in the child form i have CANCEL button that suppose to teminate the application if the user press YES.
I added to the click event the following code:
private void btnCancel_Click(object sender, EventArgs e)
{
Application.Exit();
}
And now I am having the problem.
I am getting an error when I try to cancel the program and the error points to the cancel button, application.exit();
How can I terminate the program from runnning when pressing the cancel button?
Thanks
VBDC
|
|
|
|
|
Hi,
I tried to reproduce the error that you are referring here, but couldn't reproduce it.
The MDI parent form's closing event is not firing because you are calling Application.Exit() in the Child form, which closes the entire epplication.
May be some other code you have is creating the error.
Blumen
I wish to become a software consultant.
|
|
|
|
|
Hi to All,
My English is not native, sorry.
Ok, I have MDI form and Child form.
in the MDI code file I added "Form_Closing" event.
private void frmMainMdi_FormClosing(object sender, FormClosingEventArgs e)
{
// Hold the MessageBox button pressed
DialogResult diaResult;
// Show Message to the User
diaResult = MessageBox.Show("Are you sure you want to cancel the setup?",
"Exit Setup",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button2);
// Checking which button as been pressed
if (diaResult == DialogResult.No)
{
// CANCEL pressed, set focus to the program
e.Cancel = true;
}
else
{
// YES pressed, exit the program
this.Dispose();
Application.Exit();
}
}
Now, In the child form I have CANCEL button that suppose to close the application if the user press "YES".
I added to the cancel button click event:
Applicarion.exit();
and then I am having an error.
How can I close the program from the child form using the Form_Closing event from the MDI form.
Thanks
VBDC
|
|
|
|
|
I have to implement A peer-to-peer text messaging application . the idea is as follows.
Please has anyone designed a similar application ! i would be very greatful if u can help ?
In a client- server paradigm clients never communicate directly with each other. This often leads to the centralisation of user interaction. The peer-to-peer (p2p) model tried to overcome this problem. In a p2p model, users cannot communicate directly with each other. It may be helpful to view a ‘peer process’ as an entity incorporating a client and a server within it.
A peer process typically uses a central server, a peer-directory, to find out about other peer processes in the system. Peer-directory maintains a table whereby the address and port number of a peer is mapped on to a single integer index. Peers identify each other by this index number. We will refer to this index number a peer-id.
The central server or the peer-directory provides a mechanism whereby peers can coordinate their interaction in time and pace. However, the rest of the interaction can then be conducted directly, without the need for the central server. In this way, significant reduction of centralized communication can be achieved and a more distributed pattern of network usage is created. In a peer-to-peer text system the central server maintains a table where information on member is stored. Whenever a new member subscribes into the system, the central server sends the updated table to all members of the group. Peers send text messages directly to each other.
Centre peer. The interaction between peer and peer directory can be organized in such a way that peers are automatically notified whenever a new member enters or exit the peer group.
|
|
|
|
|
This reads like a homework assignment. What bits are you stuck with ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|