Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I'm Using a silver-light file upload control in asp.net application. Its of similar structure as written below, now While debugging localhost:55000/FileUpload.ashx uploads (eventualy copy on same machine) the file properly, but when i use /FileUpload.ashx of an hosted application, is doesn't do any thing, infact FileUpload.ashx is never called.

C#
public const int CHUNK_SIZE = 4096; 
public const string UPLOAD_URI = "http://localhost:55000/FileUpload.ashx?filename={0}&append={1}"; 
private Stream _data; 
private string _fileName; 
private long
_bytesTotal; 
private long _bytesUploaded;   
private void UploadFileChunk() 
{
    string uploadUri = ""; // Format the upload URI according to wether the it's the first chunk of the file
    if (_bytesUploaded == 0)
    {
        uploadUri = String.Format(UPLOAD_URI,_fileName,0); // Dont't append
    }
    else if (_bytesUploaded < _bytesTotal)
    {
        uploadUri = String.Format(UPLOAD_URI, _fileName, 1); // append
    }
    else
    {
        return;  // Upload finished
    }

    byte[] fileContent = new byte[CHUNK_SIZE];
    _data.Read(fileContent, 0, CHUNK_SIZE);

    WebClient wc = new WebClient();
    wc.OpenWriteCompleted += new OpenWriteCompletedEventHandler(wc_OpenWriteCompleted);
    Uri u = new Uri(uploadUri);
    wc.OpenWriteAsync(u, null, fileContent);
    _bytesUploaded += fileContent.Length; 
}   

void wc_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) 
{
    if (e.Error == null)
    {   
        object[] objArr = e.UserState as object[];
        byte[] fileContent = objArr[0] as byte[];
        int bytesRead = Convert.ToInt32(objArr[1]);
        Stream outputStream = e.Result;
        outputStream.Write(fileContent, 0, bytesRead);
        outputStream.Close();
        if (_bytesUploaded < _bytesTotal)
        {
            UploadFileChunk();
        }
        else
        {
            // Upload complete
        }
    } 
}
Posted

1 solution

You have to give elevated permissions as described at Silverlight Elevated Permissions
[^]. Full Trust permissions are what you should aim for..
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900