Creating File Uploader For Window Phone 7

By Abhishek Shukla

Creating File Uploader For Window Phone 7

This is very basic level small user control, in which we can discuss how to create web user control.

To create user controls follow the steps:

- Right click on project

- Click on Add

- Select New Item

- Select Web User Control

- Specify some Name

I have given name to this file as “uploader.ascx” and kept this file under “userControl” for simplicity purpose.

On this page I am having following controls:

 

1:     "fileUpload" type="file" Runat="server" NAME="fileUpload">
2:
3:     "lblMessage" runat="server" Width="416px" Font-Size="10" Font-Name="verdana">
4:
5:     "btnSave" runat="server" Text="Upload..">
6:
7: At the code behind of above file I am having following function
8:
9: public string uploadFile(string fileName,string folderName)
10:
11: {
12:
13:           if(fileName=="")
14:
15:           {
16:
17:                     return "Invalid filename supplied";
18:
19:           }
20:
21:           if(fileUpload.PostedFile.ContentLength==0)
22:
23:           {
24:
25:                     return "Invalid file content";
26:
27:           }
28:
29:                     fileName = System.IO.Path.GetFileName(fileName);
30:
31:           if(folderName=="")
32:
33:                     {
34:
35:                     return "Path not found";
36:
37:                     }
38:
39:                     try
40:
41:                     {
42:
43:                     if (fileUpload.PostedFile.ContentLength
22:

 

i.e. I have set up path of folder to upload image

To access control in project, I have added page called as “uploadTester.aspx” to the project in which I have added following line:

Which says that this control is register to this page with specified source.

And in HTML code I have added following code inside form tag:

That’s all about

 

General:

To upload any of the file in respective folder user need to have permission for writing to the folder so please follow the following steps to prevent from the error.

Set permission to virtual directory by following steps in IIS

- Right Click on virtual directory which you have created for this project. Under directory Tab you will find

1)Read 2)Log Visits 3)Index this resources Are marked as checked (enables) in addition to this make 4)Write access enabled or checked

- Click on apply

- Click on ok

This will set right permission to entire virtual directory, this way we can minimize error from the front end for permission / access denied.

Other way to solve permission denied issue is to go to actual folder “images” by using physical path and follow these steps:

- Right click folder

- Sharing Tab

- Enable share this folder radio button

- Click Apply

- Click Ok

If u are using this code on 2000 server you should do following:

- Right click respective folder

- Go to security tab

- Select Everyone user

- Apply full control

- click on ok

 

Please Do comment!

- Click on Add

- Select New Item

- Select Web User Control

- Specify some Name

I have given name to this file as “uploader.ascx” and kept this file un