|
Try the WebClient class...
Chris
|
|
|
|
|
There's an example here[^]. Good luck
I are Troll
|
|
|
|
|
Hi,
I want to download 10 mb file from URL or FTP. downloading is in progress and 5MB downloaded, now i want to cancel the download. Next time the application should download remaining 5 MB.
How to do it?
Reply ASAP.
Thanking You,
Sunil G.
|
|
|
|
|
Sunil G wrote: How to do it?
Using BITS[^]. Divide the data over two zipfiles and download them.
Sunil G wrote: Reply ASAP.
Whehe, you failed to specify in which year I should reply - so I assumed "this" year
I are Troll
|
|
|
|
|
RegEdit Copy Key Name for Microsoft Office 10.0 is "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0". So why is registry equal to null in "registry = Registry.LocalMachine.OpenSubKey( @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0", false);" in the following C# 2008 code?
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace MSKeyFinder
{
public partial class frmMain : Form
{
private const int CS_DROPSHADOW = 0x00020000;
public frmMain()
{
InitializeComponent();
}
protected override CreateParams CreateParams
{
get
{
CreateParams p = base.CreateParams;
p.ClassStyle |= CS_DROPSHADOW;
return p;
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
byte[] digitalProductId = null;
RegistryKey registry = null;
try
{
registry = Registry.LocalMachine.OpenSubKey(
@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0", false);
}
catch (System.Exception ex)
{
string caption = "Error";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBoxIcon icon = MessageBoxIcon.Error;
MessageBox.Show(ex.Message, caption, buttons, icon);
Environment.Exit(0);
}
finally
{
if (registry == null)
{
string message = "Microsoft Office (TM) XP not installed or error\r\n" +
"reading Registry (Registry.LocalMachine.OpenSubKey returned null).";
string caption = "Error";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBoxIcon icon = MessageBoxIcon.Error;
MessageBox.Show(message, caption, buttons, icon);
Environment.Exit(0);
}
else
{
registry.Close();
lblOffVersion.Text = (string)"Microsoft Office (TM) 2002";
digitalProductId = registry.GetValue("DigitalProductID") as byte[];
lblOffiProductKey.Text = (string)DecodeProductKey(digitalProductId);
}
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
About dlgForm1 = new About();
dlgForm1.ShowDialog();
}
public static byte[] GetRegistryDigitalProductID()
{
byte[] digitalProductId = null;
RegistryKey registry = null; ;
try
{
registry = Registry.LocalMachine.OpenSubKey(
@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Registration\" +
@"{91110409-6000-11D3-8CFE-0050048383C9}", false);
}
catch (System.Exception ex)
{
registry.Close();
string caption = "Error";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBoxIcon icon = MessageBoxIcon.Error;
MessageBox.Show(ex.Message, caption, buttons, icon);
Environment.Exit(0);
}
finally
{
if (registry == null)
{
registry.Close();
string message = "Microsoft Office (TM) XP not installed or error\r\n" +
"reading Registry (Registry.LocalMachine.OpenSubKey returned null).";
string caption = "Error";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBoxIcon icon = MessageBoxIcon.Error;
MessageBox.Show(message, caption, buttons, icon);
Environment.Exit(0);
}
else
{
digitalProductId = registry.GetValue("DigitalProductID") as byte[];
registry.Close();
}
}
return digitalProductId;
}
public static string DecodeProductKey(byte[] digitalProductId)
{
const int keyStartIndex = 52;
const int keyEndIndex = keyStartIndex + 15;
char[] digits = new char[]
{
'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R',
'T', 'V', 'W', 'X', 'Y', '2', '3', '4', '6', '7', '8', '9',
};
const int decodeLength = 29;
const int decodeStringLength = 15;
char[] decodedChars = new char[decodeLength];
ArrayList hexPid = new ArrayList();
for (int i = keyStartIndex; i <= keyEndIndex; i++)
{
hexPid.Add(digitalProductId[i]);
}
for (int i = decodeLength - 1; i >= 0; i--)
{
if ((i + 1) % 6 == 0)
{
decodedChars[i] = '-';
}
else
{
int digitMapIndex = 0;
for (int j = decodeStringLength - 1; j >= 0; j--)
{
int byteValue = (digitMapIndex << 8) | (byte)hexPid[j];
hexPid[j] = (byte)(byteValue / 24);
digitMapIndex = byteValue % 24;
decodedChars[i] = digits[digitMapIndex];
}
}
}
return new string(decodedChars);
}
private void timer1_Tick(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = DateTime.Now.ToShortTimeString();
}
}
}
|
|
|
|
|
Closed this question. I figured it out by myself.
|
|
|
|
|
spicture wrote: I figured it out by myself.
So you are also Member 6677969?
Why? So you can vote yourself up?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You can't do that anyway - or at least not from the same IP address
|
|
|
|
|
Member 6677969 wrote: So why is registry equal to null
The method OpenSubKey returns NULL if the operation failed, as stated in the documentation[^]. This is probably a permission-related issue.
Why would that be? Well, simple; the only reason why someone would want to read that key is to use it on another machine.
I are Troll
|
|
|
|
|
hi, regarding to an article I've read, adding Enlist=true parameter to connection string is enough to add that connection to the pool. I've done and didn't get any errors.Is it done now? Have I implemented the pool in the right way? because I didn't realize any difference
|
|
|
|
|
teknolog123 wrote: regarding to an article I've read
Know one knows what article you are talking about - could you post a link please?
|
|
|
|
|
in fact, I didn't mean to ask you to verify the correctness of the article. Instead, is it enough to add Enlist=true pm to implement the pool
|
|
|
|
|
I expect it has no effect on ADO.NET, which always wants to use a pool anyway, but I could be wrong.
Perhaps the database forum would be a better choice.
|
|
|
|
|
teknolog123 wrote: regarding to an article I've read, adding Enlist=true parameter to connection string is enough to add that connection to the pool. I've done and didn't get any errors.Is it done now?
I'm betting 2 cents that you're not referring to an article from CodeProject
The Enlist parameter isn't going to influence connection pooling[^]. I believe that pooling is the default behaviour for all providers, with the exception of ODBC.
I are Troll
|
|
|
|
|
i m using following code to set Datasource of gridview but its not working plz help
string path = Directory.GetCurrentDirectory();
string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\cricketdb.mdb";
OleDbConnection con = new OleDbConnection(conn);
OleDbCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM countryinfo";
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet("countryinfo");
OleDbCommandBuilder oldbcbr = new OleDbCommandBuilder(da);
da.Fill(ds, "countryinfo");
dataGridView1.DataSource = ds;
comboBox2.DataSource = ds.Tables["Country_Name"];
listBox1.DataSource = ds.DefaultViewManager;
listBox1.DisplayMember = "Country_Name";
dataGridView1.DataSource = ds;
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
comboBox2.DataSource = dt;
Its also not setting datasource of anycontrol like combo or list plz help
|
|
|
|
|
Is it shows any error ?
Life's Like a mirror. Smile at it & it smiles back at you.- P Pilgrim
So Smile Please
|
|
|
|
|
No it does not compiles any error but display nothing in gridview
|
|
|
|
|
shaina2231 wrote: comboBox2.DataSource = ds.Tables["Country_Name"];
what is Country_Name ?
I think you have to use instead
comboBox2.DataSource = ds.Tables[0];
Life's Like a mirror. Smile at it & it smiles back at you.- P Pilgrim
So Smile Please
|
|
|
|
|
Hi,
I am using webclient while uploading large file(135MB) using windows application. My Code works but when it reaches to stream.close() it showing following error
Error:-
The CLR has been unable to transition from COM context 0x1ff030 to
COM context 0x1ff1a0 for 60 seconds. The thread that owns the destination
context/apartment is most likely either doing a non pumping wait or processing
a very long running operation without pumping Windows messages. This situation
generally has a negative performance impact and may even lead to the application
becoming non responsive or memory usage accumulating continually over time.
To avoid this problem, all single threaded apartment (STA) threads should use
pumping wait primitives (such as CoWaitForMultipleHandles) and routinely
pump messages during long running operations.
So because of that my file is not uploaded. what is the problem?
My Code is:-
WebClient client = new WebClient();
Stream stream = client.OpenWrite(remoteFilename, "PUT");
// The buffer size is set to 2kb
const int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
// Opens a file stream (System.IO.FileStream) to read the file
// to be uploaded
FileStream fs = fileInf.OpenRead();
int doneSoFar = 0;
// Read from the file stream 2kb at a time
contentLen = fs.Read(buff, 0, buffLength);
//added for accurate progress
doneSoFar += contentLen;
setItemStatus("Uploading");
while (contentLen != 0)
{
setItemProgress(doneSoFar, fileInf.Length);
// Write Content from the file stream to the FTP Upload Stream
stream.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
doneSoFar += contentLen;
}
// Close the file stream and the Request Stream
stream.Close();
fs.Close();
Thanks
sjs
|
|
|
|
|
First, please format any code you post using the pre tags.
Have you tried just using WebClient.UploadFile or WebClient.UploadFileAsync ?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Ok. Let me specify what I am actually doing.
I am using windows application for uploading file on server. My client applications were using by our various CLIENT's. In that I am using one folder where there will be more files in that and once CLIENT's finish there work they save it to that folder. then by using threading concept I am fetching all the files and uploaded on the server. Also in that I need to check the size of files that is being uploaded on the server.
In that I dont want to set some credential like username and password.
By using your solution webclient.uploadfile() is this will work.
How can i use Webclient.UploadfileAsync?
Thanks
sjs
modified on Saturday, April 10, 2010 7:38 AM
|
|
|
|
|
sjs4u wrote: Let me specify what I am actually doing.
That would have nice to do in the first post.
sjs4u wrote: webclient.uploadfile() is this will work.
Why?
sjs4u wrote: How can i use Webclient.UploadfileAsync?
RTFM
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
webclient.uploadfile() :- for This should I have to write credential? Right Now my path is http://loacalhost/server/file.wav.
as i m uploading .wav file.
Why I am saying that I want to use same code only for uploading the file.
I will check..Thanks
|
|
|
|
|
sjs4u wrote: want to use same code only for uploading the file.
What???
sjs4u wrote: This should I have to write credential?
Why? Does the website you are posting to require login?
sjs4u wrote: I will check
This is the only part of your response that makes sense
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I have two textbox BP_S and BP_D
how can I make sure if one textbox is not null then the other should not be null as well... && and || won't worked I guess..
|
|
|
|