Click here to Skip to main content
15,909,199 members
Home / Discussions / C#
   

C#

 
QuestionRe: Another managed/unmanaged problem Pin
Kasic Slobodan15-Sep-06 7:53
Kasic Slobodan15-Sep-06 7:53 
AnswerRe: Another managed/unmanaged problem Pin
Nader Elshehabi15-Sep-06 12:38
Nader Elshehabi15-Sep-06 12:38 
GeneralRe: Another managed/unmanaged problem Pin
Kasic Slobodan16-Sep-06 1:29
Kasic Slobodan16-Sep-06 1:29 
GeneralRe: Another managed/unmanaged problem Pin
Nader Elshehabi16-Sep-06 1:44
Nader Elshehabi16-Sep-06 1:44 
GeneralRe: Another managed/unmanaged problem [modified] Pin
Kasic Slobodan17-Sep-06 1:12
Kasic Slobodan17-Sep-06 1:12 
QuestionHow can I download video files programmatically in C# [modified] Pin
desamsetty14-Sep-06 13:18
desamsetty14-Sep-06 13:18 
AnswerRe: How can I download video files programmatically in C# Pin
Dominic Pettifer14-Sep-06 13:35
Dominic Pettifer14-Sep-06 13:35 
AnswerRe: How can I download video files programmatically in C# Pin
scott_hackett18-Sep-06 21:22
scott_hackett18-Sep-06 21:22 
Similar to something I posted a few messages up... you'll want to modify this to be a bit more asynchronous, especially if you're downloading large files like videos. This function downloads the contents of the web file and stores it in a temp file and returns the temp file name.

public string GetWebFile(string url)
{
    HttpWebRequest webRequest = null;
    HttpWebResponse webResponse = null;
    Stream responseStream = null;
    FileStream fileStream = null;
    string filename = "";

    try
    {
        // Create the web request
        webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
        // Get the response
        webResponse = (HttpWebResponse)webRequest.GetResponse();
        // Get the response stream
        responseStream = webResponse.GetResponseStream();
        // write it to a temporary file in 1000 byte chunks
        filename = Path.GetTempFileName();
        fileStream = new FileStream(filename, FileMode.Append);
        int bytesRead = 0;
        byte[] data = new byte[1000];
        // keep looping until we read nothing
        do
        {
            // read the next 1000 bytes of data
            bytesRead = responseStream.Read(data, 0, 1000);
            // write the data to the file
            fileStream.Write(data, 0, bytesRead);
        }
        while (bytesRead > 0);
    }
    catch (Exception e)
    {
        MessageBox.Show("Error : " + e.Message);
    }
    finally
    {
        // free any resources
        if (fileStream != null)
        {
            fileStream.Close();
            fileStream.Dispose();
        }
        if (responseStream != null)
        {
            responseStream.Close();
            responseStream.Dispose();
        }
        if (webResponse != null)
        {
            webResponse.Close();
        }
    }

    // return the contents
    return filename;
}

QuestionMemory Leak in C#.NET 2005 Pin
clint198214-Sep-06 10:31
clint198214-Sep-06 10:31 
AnswerRe: Memory Leak in C#.NET 2005 Pin
Christian Graus14-Sep-06 13:49
protectorChristian Graus14-Sep-06 13:49 
GeneralRe: Memory Leak in C#.NET 2005 Pin
clint198215-Sep-06 22:19
clint198215-Sep-06 22:19 
AnswerRe: Memory Leak in C#.NET 2005 Pin
Hamid_RT15-Sep-06 6:41
Hamid_RT15-Sep-06 6:41 
QuestionReturning Key-Value Pairs from Web Service Pin
DISP-Jol14-Sep-06 10:25
DISP-Jol14-Sep-06 10:25 
QuestionPulling values from xml nodes where xml is in string form Pin
Omkar Ghaisas14-Sep-06 9:04
Omkar Ghaisas14-Sep-06 9:04 
AnswerRe: Pulling values from xml nodes where xml is in string form Pin
Stefan Troschuetz14-Sep-06 9:17
Stefan Troschuetz14-Sep-06 9:17 
QuestionWay for a Method() to get the class name of it's caller? Pin
Dominic Pettifer14-Sep-06 8:34
Dominic Pettifer14-Sep-06 8:34 
AnswerRe: Way for a Method() to get the class name of it's caller? Pin
mav.northwind14-Sep-06 8:52
mav.northwind14-Sep-06 8:52 
GeneralRe: Way for a Method() to get the class name of it's caller? Pin
Dominic Pettifer14-Sep-06 11:11
Dominic Pettifer14-Sep-06 11:11 
QuestionSave encrypted data to SQL Server with funny chars Pin
MyRunner2314-Sep-06 7:53
MyRunner2314-Sep-06 7:53 
AnswerRe: Save encrypted data to SQL Server with funny chars Pin
Rob Graham14-Sep-06 8:01
Rob Graham14-Sep-06 8:01 
GeneralRe: Save encrypted data to SQL Server with funny chars Pin
MyRunner2314-Sep-06 8:10
MyRunner2314-Sep-06 8:10 
GeneralRe: Save encrypted data to SQL Server with funny chars Pin
Dominic Pettifer14-Sep-06 8:27
Dominic Pettifer14-Sep-06 8:27 
AnswerRe: Save encrypted data to SQL Server with funny chars Pin
Judah Gabriel Himango14-Sep-06 8:36
sponsorJudah Gabriel Himango14-Sep-06 8:36 
QuestionlistView Pin
TAREQ F ABUZUHRI14-Sep-06 7:41
TAREQ F ABUZUHRI14-Sep-06 7:41 
AnswerRe: listView Pin
Judah Gabriel Himango14-Sep-06 8:38
sponsorJudah Gabriel Himango14-Sep-06 8:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.