|
I have a VS2005 web project that provides file content download. Since some files are large I want to be able to pause/resume the download. I have added the 'Range' header and byte marker but am getting two problems:
1) File name is getting corrupted with a ',' comma character on the end of the file name (i.e. 'File.zip' shows in the save dialog as 'file.zip,' - could this be a cached file name suggestion?
2) The resume won't fire (possibly due to problem 1)
Environment is IIS6, VS2k5/C#/ASPX.
Have tried with FireFox (3.5.2) and Internet Download manager.
Here's the code - TIA
<br />
if (File.Exists(strFilePath))<br />
{<br />
byte[] buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])];<br />
int length;<br />
long dataToRead, dataLength, bytesDownloaded;<br />
long start = 0;<br />
<br />
string range = Request.Headers["Range"];<br />
if (range != null)<br />
{<br />
range = range.Replace("bytes=", "");<br />
range = range.Substring(0, range.IndexOf("-"));<br />
start = Int64.Parse(range);<br />
}<br />
Response.Expires = 0;<br />
bytesDownloaded = 0;<br />
using (FileStream dlStream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))<br />
{<br />
if (start > 0)<br />
{<br />
dlStream.Seek(start, SeekOrigin.Begin);<br />
dataToRead = dlStream.Length - start;<br />
}<br />
else<br />
{ dataToRead = dlStream.Length; }<br />
dataLength = dataToRead;<br />
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + dlStream.Name.Substring(dlStream.Name.LastIndexOf(@"\") + 1) + "\"");<br />
Response.AddHeader("Content-Length", dlStream.Length.ToString());<br />
length = dlStream.Read(buffer, 0, Int32.Parse(Config.Settings["bufferSize"]));<br />
while (dataToRead > 0)<br />
{<br />
if (Response.IsClientConnected)<br />
{<br />
Response.OutputStream.Write(buffer, 0, length);<br />
bytesDownloaded += length;<br />
Response.Flush();<br />
buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])];<br />
dataToRead -= length;<br />
}<br />
else<br />
{ break; }<br />
}<br />
try <br />
{ dlStream.Close(); }<br />
catch<br />
{<br />
if (dlStream != null)<br />
{<br />
_errors.SendErrorEmail("download.aspx", "failed to close the file stream when user " + objUser.LoginID + " attempted to download " + strFilePath + ".", objUser);<br />
}<br />
}<br />
}<br />
<br /> ;
Thank you for taking the time to look at this
Tom
|
|
|
|
|
TCHamilton wrote: Since some files are large I want to be able to pause/resume the download.
In that case, why not check out the Background Intelligent Transfer Service[^]?
"I do not care if it works on your system, I am not gonna ship your computer."
|
|
|
|
|
Hi Eddy,
I'm not familiar yet with BITS - will explore now. The issue really is how/what's missing in my attempt to facilitate 'resume a paused download...'
Web site is public facing that supports various browsers - I've been asked to make sure it can handle IE6 and Safari primarily, not sure if BITS is relevent in that context. I'm sure the target browser limitation will relax, but first I need to get 'resume' to work.
Tom
|
|
|
|
|
Check this post. This might help.
|
|
|
|
|
Still having problem - unable to set the Response Headers :
Response.AddHeader("Content-Disposition", "attachment; filename=" + Convert.ToString(Server.UrlDecode(Request["FileName"])));
Response.AddHeader("Content-Length", dlStream.Length.ToString());
The system gives message that:
Headers: 'Response.Headers' threw an exception of type 'System.PlatformNotSupportedException'
The system is Win2k3 IIS6. VS2k5
Confused...
Thank you for any help or suggestions
Tom
|
|
|
|
|
Well, mystery solved - response headers were being set, just not obvious with IIS 6, have to track them down via DEBUG/Watch with code that can enum the Custom Header array
((System.Web.HttpResponseHeader)((new System.Collections.ArrayList.ArrayListDebugView(Response._customHeaders)).Items[0])).Name "Accept-Ranges"<br />
((System.Web.HttpResponseHeader)((new System.Collections.ArrayList.ArrayListDebugView(Response._customHeaders)).Items[0])).Value "bytes"
Able to verify Header set, and respond to resume download 'Range'
Thanks all
Tom
|
|
|
|
|
I'm starting a new project and just had a few questions. Please excuse me if these seem trivial, but I have just recently taken on programming in Windows as a career. Although, I know more than enough to be dangerous.
1. This project is set to be complete Feb 1. VS2010 should be out by then. Should I used the beta version now to develop with or use VS2008 and upgrade the project when it comes out?
2. This project is porting our current application written in VB6 to C#. Are there any methods, best practices, or tools that might be helpful or make the transition easier?
3. I'd like to use WPF just because it seems like the new front end for MS, plus I like all new graphical features it brings to the table. I've been hearing a lot about if you're using WPF you should consider MVVM. Is it worth implementing MVVM now or is it something that can be done later? I realize it's always better to do it now, but I don't know much about it (although I have bookmarked Sacha Barber's articles). I don't want to jeopardize the release date for something that will not affect the user or functionality of the machine (it's an automated tooling machine). I've got several user controls that I need to update as well. Some of them are very fancy user input controls. Should this affect my decision?
Thanks for your help and suggestions. I appreciate it.
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|
|
BRShroyer wrote: 1. This project is set to be complete Feb 1. VS2010 should be out by then. Should I used the beta version now to develop with or use VS2008 and upgrade the project when it comes out?
Whatever? Compare it to learning a language, you're asking whether you should learn British or American. I'd say that either language empower you in roughly the same way, and the basic tactics will outlast the language itself. Meaning, we still speak in the same way whenever a dictionary changes.
BRShroyer wrote: 2. This project is porting our current application written in VB6 to C#. Are there any methods, best practices, or tools that might be helpful or make the transition easier?
Get the Interop Toolkit[^], and you can replace your VB6-forms one by one with .NET counterparts. There's an example on using the BackgroundWorker in VB6
"If you owe the bank $100, that's your problem. If you owe the bank $100 million, that's the bank's problem."
-- John Paul Getty
|
|
|
|
|
Well you seem to have set yourself (or been set) a goodly challenge!
1. The target date should not be used to decide what tools to use. I would suggest using the most up to date version of VS that is currently available (i.e VS2008) rather than worrying what might be available towards the end of the year. Chances are you need to be productive now, and not worrying about beta software.
2. Not sure of the answer to this one but I expect a Google search will get you to any tools that can do VB to C# conversions. Once you find a tool that works then try to convert the code then go through your compile and test phases; my guess is that that will keep you busy until February.
3. The phrasing of your question suggests that you are not yet a WPF expert. I would not advise trying to convert VB direct to WPF - the learning curve is quite steep. WPF certainly does some wonderful things but you really need to have a very good understanding of how it all fits together to get it right. if you ARE as good as Sacha, Josh or Karl (and all the others) then sure go for it, but if you are a novice then don't try yet. Same answer for MVVM, it's a great pattern, but you really need to understand how it all fits together before trying it on an operational project.
good luck,
Richard
modified on Wednesday, August 26, 2009 9:23 AM
|
|
|
|
|
Hi
we have visual studio 2008 team system.
we're looking for a way to config this product to implement team working and give us a feature to working our developers on the same project (in serevral machines on the network).
would u plz help me how to accomplish this.
thanks
|
|
|
|
|
I am trying to make a program send the email message in a given textbox (here, messageTextBox) when you click on a "Send" button. I cannot seem to get this to work. I am just wondering if someone maybe had some input that would be useful. I am doing this for a website project & have been using my personal emails to test & so far, no luck. Thanks for any & all input!!
protected void sendButton_Click(object sender, EventArgs e)
{
//create mail message
MailMessage mail = new MailMessage();
//set the address
mail.From = new MailAddress("****@yahoo.com");
mail.To.Add("*****@hotmail.com");
//set the content
mail.Subject = "Project email";
mail.Body = messageTextBox.ToString();
//send the message
SmtpClient smtp = new SmtpClient("localhost");
smtp.Credentials = new System.Net.NetworkCredential("****@yahoo.com", "myPassword");
smtp.Host = "mail.yahoo.com";
smtp.Port = 25;
smtp.Send(mail);
}
|
|
|
|
|
Seems the smtp server you are trying to use is not valid.SmtpClient.Host should be a valid smtp server.I suppose yahoo smtp server is smtp.mail.yahoo.com and the port is 465,not 25.So try to modify your code like that:
smtp.Host="smtp.mail.yahoo.com";
smtp.Port=465;
Here is an article how to send email through gmail account.
Life is a stage and we are all actors!
|
|
|
|
|
|
What do you want the result to be? I don't understand what "d= x(square) x*y y(square) x y 1" means
|
|
|
|
|
its a design matrix
d = x[0](square) x[0]*y[0] y[0](square) x[0] y[0] 1
x[1](square) x[1]*y[0] y[1](square) x[1] y[1] 1
....
....
.....
till x[4] y[4]
|
|
|
|
|
So look at your latest message and count the numbers across and the lines down; that should tell you what kind of 2D array you are needing.
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.
|
|
|
|
|
Please do not delete or empty a message, it is against the forum rules as it causes messy threads no one can understand.
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.
|
|
|
|
|
I've had success having an individual (one at a time) to perform reading serial number from the file and increment by one and save the new number in this .log file.
However is that I'm trying to determine the best approach for each process to wait for the file access while one of the process is using the file. Once the file is ready for read/write, then the other process can use the file.
Sample code for each process (pretty much the same for the 4 processes:
--------
private void RunProcess1()
{
while (fileHandle != IntPtr.Zero)
{
lblStatus1.BackColor = Color.Yellow;
lblStatus1.Text = "Awaiting Accessing Serial file...";
Application.DoEvents();
for (int m = 0; m < 100000; m++)
Application.DoEvents();
}
//do
//{
try
{
lblStatus1.BackColor = Color.Magenta;
lblStatus1.Text = "Accessing Serial file";
Application.DoEvents();
FileStream filestream = new FileStream("serial.log", FileMode.OpenOrCreate, FileAccess.Read, FileShare.None);
fileHandle = filestream.Handle;
StreamReader tr = new StreamReader(filestream);
count = Convert.ToInt32(tr.ReadLine(), 10);
lblSerial1.Text = count.ToString();
tr.Close();
lblStatus1.BackColor = Color.Lime;
lblStatus1.Text = "Saving Serial file";
Application.DoEvents();
filestream = new FileStream("serial.log", FileMode.Create, FileAccess.Write, FileShare.None);
StreamWriter sw = new StreamWriter(filestream);
sw.Write(++count);
sw.Flush();
lblStatus1.BackColor = Color.Green;
for (int m = 0; m < 1000000; m++)
Application.DoEvents();
sw.Close();
lblStatus1.BackColor = defaultBackground;
lblStatus1.Text = "Success!";
Application.DoEvents();
//timer1.Start();
fileHandle = IntPtr.Zero;
}
catch (Exception err)
{
//timer1.Stop();
//proc1Success = false;
}
//} while (proc1Success == false);
}
|
|
|
|
|
no PRE tags ==> no help
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.
|
|
|
|
|
I've had success having an individual (one at a time) to perform reading serial number from the file and increment by one and save the new number in this .log file.
However is that I'm trying to determine the best approach for each process to wait for the file access while one of the process is using the file. Once the file is ready for read/write, then the other process can use the file.
Sample code for each process (pretty much the same for the 4 processes:
--------
private void RunProcess1()
{
while (fileHandle != IntPtr.Zero)
{
lblStatus1.BackColor = Color.Yellow;
lblStatus1.Text = "Awaiting Accessing Serial file...";
Application.DoEvents();
for (int m = 0; m < 100000; m++)
Application.DoEvents();
}
//do
//{
try
{
lblStatus1.BackColor = Color.Magenta;
lblStatus1.Text = "Accessing Serial file";
Application.DoEvents();
FileStream filestream = new FileStream("serial.log", FileMode.OpenOrCreate, FileAccess.Read, FileShare.None);
fileHandle = filestream.Handle;
StreamReader tr = new StreamReader(filestream);
count = Convert.ToInt32(tr.ReadLine(), 10);
lblSerial1.Text = count.ToString();
tr.Close();
lblStatus1.BackColor = Color.Lime;
lblStatus1.Text = "Saving Serial file";
Application.DoEvents();
filestream = new FileStream("serial.log", FileMode.Create, FileAccess.Write, FileShare.None);
StreamWriter sw = new StreamWriter(filestream);
sw.Write(++count);
sw.Flush();
lblStatus1.BackColor = Color.Green;
for (int m = 0; m < 1000000; m++)
Application.DoEvents();
sw.Close();
lblStatus1.BackColor = defaultBackground;
lblStatus1.Text = "Success!";
Application.DoEvents();
//timer1.Start();
fileHandle = IntPtr.Zero;
}
catch (Exception err)
{
//timer1.Stop();
//proc1Success = false;
}
//} while (proc1Success == false);
}
|
|
|
|
|
I did not get into your code as I think you have a design problem, 2 issues.
Why are you logging to a text file and wanting database functionality. Why not use a database as a log destination.
Why are you waiting for the file to be released. Stick a queue in front of the write and have your methods load the queue (this is only required b/c you are using a text file).
|
|
|
|
|
Hi,
While adding the project output to the setup project, I got the following message.
"The following files may have dependencies that cannot be determined automatically. Please confirm that all dependencies have been added to the project
c:\program files\ultra office control\officectrl.ocx"
Please guide me to solve this issue.
Thanks in advance..
|
|
|
|
|
It says that this setup deployment creation cannot confirm that file: officectrl.ocx doesn't have other dependancy. I suggest contact them or ignore this message and try install in clean os or In virtual machine such as VirtualBox
|
|
|
|
|
I ignored the message and installed the setup in my system itself. It opened the exe but unable to perform the operation, which uses Officectrl.ocx.
|
|
|
|
|
Did you registerd ocx by using RegSvr32.exe?
Try installing the controler on test server. If you bought it, try looking into their documentation or email them
|
|
|
|