|
Try changing the name of the tables:
MyDataSet2.Tables[0].Name = "First Table";
MyDataSet2.Tables[1].Name = "Second Table";
You should be able to rename the tables in the collection.
|
|
|
|
|
I have a method that basically takes a response stream and saves it to a file. This works fine. I want to be able to add a resume feature to this method.
Any suggestions?
My method:
private void WriteToFile(Stream response, Stream output, long sz)
{
if (sz == 0)
{
return;
}
byte[] buffer = new byte[1024 * 64];
long read = 0;
long totalRead = 0;
while ((read = response.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, Convert.ToInt32(read));
totalRead += read;
output.Flush();
}
}
|
|
|
|
|
You have to require the stream to be a seakable stream and then you can just set the position of the stream using the Position property.
Also, don't flush on each write.
byte[] buffer = new byte[1024];
int read = 0;
inputStream.Position = 0;
while((read = inputStream.Read(buffer, 0, buffer.Length)) != 0) {
outputStream.Write(buffer, 0, read);
}
outputStream.Flush();
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
1) The response stream is not seekable since it is a WebResponse.GetResponseStream(). What is my other option?
2) Why is it not a good idea to flush at every write?
|
|
|
|
|
Writing to the stream is controlled by an underlying algorithm, there is no need to flush since it forces the write which may be inefficient. If you want resume downloads using .NET you will probably have to write your own resume code based on the specification of the underlying protocol.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
This works the way it should. I havnt optimized it, so if you want to use this code, look it over and clean it up.
Read the comments. Suggestions are appreciated. Im working on optimizing my code. Too sleepy to do it today.
public void DownloadFile(System.Uri url, string filePath, long sz)
{
Stream r = null;
Stream output = GetFileStream(filePath);
System.Net.WebRequest request = System.Net.WebRequest.Create(url);
System.Net.HttpWebRequest hrequest = (System.Net.HttpWebRequest)request;
hrequest.AddRange(Convert.ToInt32(w.Length));
hrequest.UserAgent = "Mozilla/4.0 (compatiable; MSIE 7.0; Windows NT 6.0)";
System.Net.WebResponse response = null;
try
{
using (response = request.GetResponse())
{
using (r = response.GetResponseStream())
{
using (output)
{
WriteToFile(r, output, sz, w.Length);
}
}
}
}
catch (Exception ex)
{
File.Delete(filePath);
throw new Exception("Could not save " + url, ex);
}
finally
{
}
}
private Stream GetFileStream(string filePath)
{
string fileDirectory = filePath.Substring(0, filePath.LastIndexOf(@"\"));
if (!Directory.Exists(fileDirectory))
Directory.CreateDirectory(fileDirectory);
if (File.Exists(filePath))
return File.Open(filePath, FileMode.Append);
else
return File.Create(filePath);
}
private void WriteToFile(Stream response, Stream output, long sz, long initSize)
{
DateTime startTime = DateTime.Now;
if (sz == 0)
return;
byte[] buffer = new byte[1024 * 64];
long read = 0;
long totalRead = initSize;
while ((read = response.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, Convert.ToInt32(read));
}
w.Flush();
}
|
|
|
|
|
Thanks for your reply. I have done what i was trying to do. But now have another issue. May be you can help for that. it is about the xml file output when it created it showing TABLE and TABLE1 as node in xml how i can change it to meaningful name. My Code is as follows. XML file is at the bottom of the code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Xml;
using System.IO;
public partial class _Default : System.Web.UI.Page
{protected void Page_Load(object sender, EventArgs e){
GetEmployees("London");
}
public static void GetEmployees(string City){
//String sConnection = "server=HTCWEBDEMO;database=hometrust;user id=ht_admin;password=htc_tr!st";
String sConnection = "server=ZAFAR-PC\\SQLEXPRESS;Integrated Security=SSPI;database=northwind";
SqlConnection mySqlConnection = new SqlConnection(sConnection);
mySqlConnection.Open();
// Get the same data through the provider.
//string mySQLStatement = "SELECT Title,FirstName,LastName,PhoneNumber,Faxnumber, email from contactlist where TeamName='" + TeamName +"'; select FirstName, LastName from contactlist where TeamMorty ='True' and teamname='" + TeamName + "';";
string mySQLStatement = "SELECT FirstName,LastName,Title,City from employees where city= '" + City + "';select FirstName, LastName from employees where city='" + City + "';";
//SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(mySQLStatement, sConnection);
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(mySQLStatement, sConnection);
DataSet myDataSet2 = new DataSet();
myDataSet2.DataSetName = "Contacts";
mySqlDataAdapter.Fill(myDataSet2);
// Write data to files: data1.xml and data2.xml for comparison.
myDataSet2.WriteXml("c:/temp/ContactList.xml");
mySqlConnection.Close();
}
}
XML FILE OUTPUT
<?xml version="1.0" standalone="yes" ?>
- <Contacts>
- <Table>
<FirstName>Steven</FirstName>
<LastName>Buchanan</LastName>
<Title>Sales Manager</Title>
<City>London</City>
</Table>
- <Table>
<FirstName>Michael</FirstName>
<LastName>Suyama</LastName>
<Title>Sales Representative</Title>
<City>London</City>
</Table>
- <Table>
<FirstName>Robert</FirstName>
<LastName>King</LastName>
<Title>Sales Representative</Title>
<City>London</City>
</Table>
- <Table>
<FirstName>Anne</FirstName>
<LastName>Dodsworth</LastName>
<Title>Sales Representative</Title>
<City>London</City>
</Table>
- <Table1>
<FirstName>Steven</FirstName>
<LastName>Buchanan</LastName>
</Table1>
- <Table1>
<FirstName>Michael</FirstName>
<LastName>Suyama</LastName>
</Table1>
- <Table1>
<FirstName>Robert</FirstName>
<LastName>King</LastName>
</Table1>
- <Table1>
<FirstName>Anne</FirstName>
<LastName>Dodsworth</LastName>
</Table1>
</Contacts>
|
|
|
|
|
Don't post a new question as a reply in a completely unrelated thread.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I download the CaptureAndPrintMSChart project (http://www.codeproject.com/KB/cpp/capture_and_print_mschart.aspx) & tried, the MsChart working fine but when I try to print, I have the error
MSChart.EditCopy();<br />
Bitmap chartCapture = (Bitmap) Clipboard.GetDataObject().GetData("Bitmap", true);<br />
chartCapture.Save("Image.Jpeg");
- The error says that: The ExecutionEngineException was unhandled
By the way, I use the Visual Studio 2005 (Prof.), I think that is the reason (it did converted before I ran the project)
Can someone show me how to modify it?
Thank for any help
modified on Friday, October 24, 2008 3:48 PM
|
|
|
|
|
i'm trying to capture the screen when i'm playing video but when i run the code it capture the entire screen but the video region always black. It works fine in Vista but in windows XP it do the black video region problem. I have tried several ways but always same problem. Some of them are :
[DllImport("user32.dll")]
private static extern IntPtr keybd_event(int key, int dummy, int flags, IntPtr info);
keybd_event(0x2c, 0, 0, IntPtr.Zero);
Application.DoEvents();
Image tmp_I = Clipboard.GetImage();
tmp_I.Save(filePath);
Bitmap tmp_B = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(tmp_B);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), Screen.PrimaryScreen.Bounds.Size);
tmp_B.Save(filePath);
any idea guys ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
As i type text in MultiLineStringEditor it expands horinontally so is there a way to control the width of the MultilineStringEditor when text is being entered. I couldn't find anything resourcesful hope gurus can help me out here.
[Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
public override string StringProp
{
get{ return base.StringProp; }
set{ base.StringProp= value; }
}
|
|
|
|
|
DirectoryEntry employee = result.GetDirectoryEntry();
string ea = employee.Properties["proxyAddresses"].Value.ToString();
MessageBox.Show(ea.ToString());
Hi All,
i'm using the above code to try and extract the email address of a user account. if i swap proxyAddresses for 'description' or 'employeeID' etc it works fine. but when i use proxyAddresses it errors!
i have tried creating ea as a string array and it still fails!!
any ideas?
many thanks,
Phil
|
|
|
|
|
|
Hi all,
I'm trying to make the horizontal scrollbar visible by assigning true to the HorizontalScroll.Visible attribute, but it's being ignored; the value is false even right after assigning true:
mainPanel.HorizontalScroll.Visible = hScrollVisible;
mainPanel.AutoScroll is false. A Google search provides no insight. Any idea why this is happening?
|
|
|
|
|
The scroll bars are only visible when AutoScroll is set to true and it contains something that is outside of the visible area.
The HorizontalScroll property is read only so setting any of it's elements will have no effect.
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)
|
|
|
|
|
Hi,
have a look at the HScroll property, which Forms.Panel inherits from
ScrollableControl
|
|
|
|
|
|
Post back if you sort it Alan as I'd be interested in the solution! I've had a look at the source for the Panel and ScrollableControl and it seems that all the calculations that decide whether to display the scroll bars are in private methods.
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)
|
|
|
|
|
I ran into that problem too, and decided I couldn't get away from AutoScroll = true.
The trick was resetting the AutoScrollMinSize member to the ACTUAL size of the control. This causes the scrollbars to appear (correctly-sized) when the control's content exceeds the actual size.
|
|
|
|
|
Glad to see that you are back Luc
|
|
|
|
|
Hi Giorgi,
Thanks. Actually I never left, I continue reading CP articles and forums,
but I refrain from reacting or answering most questions since I am not happy
with the direction this site is taking (quantity seems far more important than
quality), and in particular I object to the black and-white voting system.
But occasionally I do enter a single message.
Regards,
|
|
|
|
|
I remember reading about it on your blog here, at CP. As for black and white voting system, the user who has asked the question can vote in the same way as it was in last.
|
|
|
|
|
|
This might help[^]
Regards,
Thomas Stockwell
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.
Visit my Blog
|
|
|
|
|
plz use Google before posting a question.
|
|
|
|