Ads by Lake Quincy Media
| Next Tip?
Home » Asp.net

File Upload in Silverlight Using WCF

19 September 2009 561 views No Comment
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.00 out of 5)
Loading ... Loading ...

In previous Articles we have discused that how we can upload a dile using .asmx web service and isolated storage space. Here in continution to the topic I am going to discuss how we can use WCF for the same purpose.

Steps :

  1. Create the a silverlight project with the “FileUploadWCF” name.
  2. Make these important changes in the properties of FileUploadWCF.Web project
    1. Right click on FileUploadWCF.Web.
    2. Select Properties
    3. Under Web tab Select Specific port and give the port number I am using port number 1366

      Note: we are using specific port so that every time we need not to run the
      web service to use it and it wont change its address. Neither we ned it to host on IIS if you don’t want to use specifc port then either host your
      web service on IIS or run the webservice every time and update the service refrence each time
      before running the application.
    4. Save The Properties Page and close it.
  3. Now Add a silverlight Comaptible WCf to the Project and name it as uploadService
  4. Include the name space “System.IO”
    <font COLOR="#0000ff">using</font> System.IO;
  5. Add a operation Contract as :

    [<font COLOR="#2b91af">OperationContract</font>]<br />
    <font COLOR="#0000ff">public</font> <font COLOR="#2b91af">List</font>&lt;<font COLOR="#0000ff">string</font>&gt;
    UploadFiles(<font COLOR="#0000ff">string</font> strFileName,
    <font COLOR="#0000ff">byte</font>[] byFile, <font COLOR="#0000ff">string</font>
    strFileNo)<br />
    {<br />
    <font COLOR="#2b91af">&nbsp;&nbsp;&nbsp; List</font>&lt;<font COLOR="#0000ff">string</font>&gt;
    result = <font COLOR="#0000ff">new</font> <font COLOR="#2b91af">List</font>&lt;<font COLOR="#0000ff">string</font>&gt;();<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp; try<br />
    &nbsp;&nbsp;&nbsp;
    </font>
    {<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //if file length is greater then 0 <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    <font COLOR="#0000ff">if</font> (byFile.Length &gt; 0)<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    {<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //set the location in a string variable where to save
    the file<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    <font COLOR="#0000ff">string</font> strFilePath = <font COLOR="#a31515">
    &quot;D:\\meet\\&quot;</font> + strFileName;<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //create a filestream<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    System.IO.<font COLOR="#2b91af">FileStream</font> fs = <font COLOR="#0000ff">
    new</font> <font COLOR="#2b91af">FileStream</font>(strFilePath,
    <font COLOR="#2b91af">FileMode</font>.Create, <font COLOR="#2b91af">FileAccess</font>.Write);<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //write the file at the specified location<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    fs.Write(byFile, 0, byFile.Length);<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //close file stream<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    fs.Close();<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    result.Add(strFileNo);<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //returm file number<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    <font COLOR="#0000ff">return</font> result;<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    {<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    result.Add(<font COLOR="#a31515">&quot;&quot;</font>); <br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return</font> result;<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }<br />
    &nbsp;&nbsp;&nbsp;
    }<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp; catch<br />
    &nbsp;&nbsp;&nbsp;
    </font>
    {<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    result.Add(<font COLOR="#a31515">&quot;&quot;</font>);<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return</font> result;<br />
    &nbsp;&nbsp;&nbsp;
    }<br />
    }

  6. Create A class "FilesClass" in FileUploadWCF project

    <font COLOR="#0000ff">public</font> <font COLOR="#0000ff">
    class</font> <font COLOR="#2b91af">FilesClass<br />
    </font>
    {<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp; public</font> FilesClass()<br />
    &nbsp;&nbsp;&nbsp;
    {<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //do nothing<br />
    &nbsp;&nbsp;&nbsp;
    </font>
    }<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp; string</font> strStatus = <font COLOR="#a31515">&quot;&quot;</font>;<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp; string</font> strNo = <font COLOR="#a31515">&quot;&quot;</font>;<br />
    &nbsp;&nbsp;&nbsp;
    FileInfo strFileName = <font COLOR="#0000ff">null</font>;<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp; public</font> <font COLOR="#0000ff">string</font>
    PropNumber<br />
    &nbsp;&nbsp;&nbsp;
    {<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    {<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return</font> strNo;<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    {<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    strNo = <font COLOR="#0000ff">value</font>;<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }<br />
    &nbsp;&nbsp;&nbsp;
    }<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp; public</font> FileInfo PropFileName<br />
    &nbsp;&nbsp;&nbsp;
    {<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>{<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return</font> strFileName;<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    {<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    strFileName = <font COLOR="#0000ff">value</font>;<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }<br />
    &nbsp;&nbsp;&nbsp;
    }<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp; public</font> <font COLOR="#0000ff">string</font>
    PropStatus<br />
    &nbsp;&nbsp;&nbsp;
    {<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    {<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return</font> strStatus;<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    {<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    strStatus = <font COLOR="#0000ff">value</font>;<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }<br />
    &nbsp;&nbsp;&nbsp;
    }<br />
    }

  7. Create Two Buttons in the Mainpage.xaml.

    1. To Chosse File
    2. To upload File At the specifed folder in the Web Service

    The Code Will look like
    <font COLOR="#a31515"><p></font><font COLOR="#0000ff">&lt;</font><font COLOR="#a31515">Grid</font><font COLOR="#ff0000">
    x</font><font COLOR="#0000ff">:</font><font COLOR="#ff0000">Name</font><font COLOR="#0000ff">=&quot;LayoutRoot&quot;</font><font COLOR="#ff0000">
    Background</font><font COLOR="#0000ff">=&quot;White&quot;</font><font COLOR="#ff0000">
    Width</font><font COLOR="#0000ff">=&quot;400&quot;</font><font COLOR="#ff0000"> Height</font><font COLOR="#0000ff">=&quot;50&quot;&gt;</p>
    </font><font COLOR="#a31515">
    <p></font><font COLOR="#0000ff">&lt;</font><font COLOR="#a31515">Button</font><font COLOR="#ff0000">
    Content</font><font COLOR="#0000ff">=&quot;Choose&quot;</font><font COLOR="#ff0000">
    Height</font><font COLOR="#0000ff">=&quot;20&quot;</font><font COLOR="#ff0000"> Width</font><font COLOR="#0000ff">=&quot;150&quot;</font><font COLOR="#ff0000">
    Click</font><font COLOR="#0000ff">=&quot;Button_Click&quot;</font><font COLOR="#ff0000">
    Margin</font><font COLOR="#0000ff">=&quot;10,0,10,10&quot;</font><font COLOR="#ff0000">
    VerticalAlignment</font><font COLOR="#0000ff">=&quot;Bottom&quot;</font><font COLOR="#ff0000">
    d</font><font COLOR="#0000ff">:</font><font COLOR="#ff0000">LayoutOverrides</font><font COLOR="#0000ff">=&quot;Width,
    Height&quot;</font><font COLOR="#ff0000"> HorizontalAlignment</font><font COLOR="#0000ff">=&quot;Left&quot;</font><font COLOR="#ff0000">
    Background</font><font COLOR="#0000ff">=&quot;#FF2770AF&quot;&gt;&lt;/</font><font COLOR="#a31515">Button</font><font COLOR="#0000ff">&gt;</p>
    </font><font COLOR="#a31515">
    <p></font><font COLOR="#0000ff">&lt;</font><font COLOR="#a31515">Button</font><font COLOR="#ff0000">
    Content</font><font COLOR="#0000ff">=&quot;Upload&quot;</font><font COLOR="#ff0000">
    Height</font><font COLOR="#0000ff">=&quot;20&quot;</font><font COLOR="#ff0000"> Width</font><font COLOR="#0000ff">=&quot;150&quot;</font><font COLOR="#ff0000">
    Click</font><font COLOR="#0000ff">=&quot;Button_Click_1&quot;</font><font COLOR="#ff0000">
    Margin</font><font COLOR="#0000ff">=&quot;20,0,10,10&quot;</font><font COLOR="#ff0000">
    VerticalAlignment</font><font COLOR="#0000ff">=&quot;Bottom&quot;</font><font COLOR="#ff0000">
    d</font><font COLOR="#0000ff">:</font><font COLOR="#ff0000">LayoutOverrides</font><font COLOR="#0000ff">=&quot;Width,
    Height&quot;</font><font COLOR="#ff0000"> HorizontalAlignment</font><font COLOR="#0000ff">=&quot;Right&quot;</font><font COLOR="#ff0000">
    Background</font><font COLOR="#0000ff">=&quot;#FF2770AF&quot;&gt;&lt;/</font><font COLOR="#a31515">Button</font><font COLOR="#0000ff">&gt;</p>
    </font><font COLOR="#a31515">
    <p></font><font COLOR="#0000ff">&lt;/</font><font COLOR="#a31515">Grid</font><font COLOR="#0000ff">&gt;</p>
    </font>

  8. Add the service refernce to the silverlight project name it “uploadService”
  9. Navigating to the event for choose button

    <font COLOR="#0000ff">private</font> <font COLOR="#0000ff">
    void</font> Button_Click(<font COLOR="#0000ff">object</font> sender,
    <font COLOR="#2b91af">RoutedEventArgs</font> e)<br />
    {<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp; //create a oblect for file open dialog<br />
    &nbsp;&nbsp;&nbsp;
    </font>
    <font COLOR="#2b91af">OpenFileDialog</font> op = <font COLOR="#0000ff">new</font>
    <font COLOR="#2b91af">OpenFileDialog</font>();<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp; //show the file browser dialog to select file<br />
    &nbsp;&nbsp;&nbsp;
    </font>
    op.ShowDialog();<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp; //if any file is selected<br />
    &nbsp;&nbsp;&nbsp;
    </font>
    <font COLOR="#0000ff">if</font> (op.File != <font COLOR="#0000ff">null</font>
    &amp;&amp; op.File.Name != <font COLOR="#a31515">&quot;&quot;</font>)<br />
    &nbsp;&nbsp;&nbsp;
    {<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //check the file size. It shoud be less than 1MB <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    <font COLOR="#0000ff">if</font> (op.File.Length &lt; 1048576)<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    {<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //create a new fill class object to maintain the file
    content <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    <font COLOR="#2b91af">FilesClass</font> obj = <font COLOR="#0000ff">new</font>
    <font COLOR="#2b91af">FilesClass</font>();<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //assign file <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    obj.PropFileName = op.File;<br /><font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//assing file number<br />
    </font>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj.PropNumber = iFileCount.ToString();
    <br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //add the file object to files list collection <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    fl.Add(obj);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    iFileCount++;<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //IF size is greater then 1 MB show the message<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    <font COLOR="#0000ff">else<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    {<br />
    <font COLOR="#2b91af">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MessageBox</font>.Show(<font COLOR="#a31515">&quot;Max file
    size is 1 MB&quot;</font>);<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }<br />
    &nbsp;&nbsp;&nbsp;
    }<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp; //display message to the user if no file is selected<br />
    &nbsp;&nbsp;&nbsp;
    </font>
    <font COLOR="#0000ff">else<br />
    &nbsp;&nbsp;&nbsp;
    </font>
    {<br />
    <font COLOR="#2b91af">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MessageBox</font>.Show(<font COLOR="#a31515">&quot;Select
    File&quot;</font>);<br />
    &nbsp;&nbsp;&nbsp;
    }<br />
    }

  10. Now Lets code for the upload event Navigate to the event

    <font COLOR="#0000ff">private</font>
    <font COLOR="#0000ff">void</font> Button_Click_1(<font COLOR="#0000ff">object</font>
    sender, <font COLOR="#2b91af">RoutedEventArgs</font> e)<br />
    {<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp; if</font> (fl.Count &gt; 0)<br />
    &nbsp;&nbsp;&nbsp;
    {<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //loop through the files and upload the files by
    passing it to web service.<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    <font COLOR="#0000ff">for</font> (<font COLOR="#0000ff">int</font> count =
    0; count &lt; fl.Count; count++)<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    { <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    uploadService.<font COLOR="#2b91af">uploadServiceClient</font> x =
    <font COLOR="#0000ff">new</font> uploadService.<font COLOR="#2b91af">uploadServiceClient</font>();<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //read the file from file class<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    <font COLOR="#2b91af">FilesClass</font> obj = (<font COLOR="#2b91af">FilesClass</font>)fl[count];<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    System.IO.<font COLOR="#2b91af">FileStream</font> str =
    obj.PropFileName.OpenRead();<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte</font>[] by = <font COLOR="#0000ff">new</font>
    <font COLOR="#0000ff">byte</font>[str.Length];<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    str.Read(by, 0, by.Length);<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    str.Close();<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //call the upload file methods async event, which will
    upload the files asynchronously<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    x.UploadFilesAsync(obj.PropFileName.Name, by, obj.PropNumber);<br />
    <font COLOR="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //here is the event hadndler, whihc will be invoked
    for every file upload<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    x.UploadFilesCompleted += <font COLOR="#0000ff">new</font> <font COLOR="#2b91af">EventHandler</font>&lt;FileUploadWCF.uploadService.<font COLOR="#2b91af">UploadFilesCompletedEventArgs</font>&gt;(UploadFileComplted);<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }<br />
    &nbsp;&nbsp;&nbsp;
    }<br />
    }<br />
    <font COLOR="#0000ff">private</font> <font COLOR="#0000ff">void</font>
    UploadFileComplted(<font COLOR="#0000ff">object</font> sender, uploadService.<font COLOR="#2b91af">UploadFilesCompletedEventArgs</font>
    e)<br />
    {<br />
    <font COLOR="#0000ff">&nbsp;&nbsp;&nbsp; if</font> (e.Result.ElementAt(0).ToString()!=<font COLOR="#a31515">&quot;&quot;</font>)<br />
    &nbsp;&nbsp;&nbsp;
    {<br />
    <font COLOR="#2b91af">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MessageBox</font>.Show(<font COLOR="#a31515">&quot;File
    Uploaded&quot;</font>);<br />
    &nbsp;&nbsp;&nbsp;
    }<br />
    }

  11. The Code Is Attached you can Download the files and enjoy file handling


    Thanks and Regards
    Meetu Choudhary
    MVP.
    My Blog || My Web || My Forums

Popularity: 12%

Post to Twitter Tweet This Post

Related posts:

  1. File Upload In silverlight using Web service (.asmx) In My Article File Handling in Silverlight I have discussed...
  2. File Handling in Silverlight ...
  3. Isolated Storage in the Silverlight Application Isolated Storage Isolated Storage in the Silverlight Application Definition: Isolated...
  4. Changing BackGround Color using JavaScript The following code shows how on button click event we...
  5. Sending Mails with attachments using Gmail Tweet This Post...

Related posts brought to you by Yet Another Related Posts Plugin.

Ads by Lake Quincy Media

Leave your response!

You must be logged in to post a comment.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes