i get this error
{"Message":"Could not find file \u0027C:\\fakepath\\001.jpeg\u0027.","StackTrace":" at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\r\n at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)\r\n at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)\r\n at System.IO.FileStream..ctor(String path, FileMode mode)\r\n at Love.WebForm2.Save(List`1 files, String name) in C:\\Users\\SERVER\
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('#btnSave').on("click", function () {
var files = new Array();
for (var i = 0; i < $("#fuUpload").prop("files").length; i++) {
var file = {};
file.Name = $("#fuUpload").prop("files")[i].name;
file.Path = $("#fuUpload").val().split(', ')[i];
files.push(file);
}
var name = $('#txtName').val();
$.ajax({
type: 'POST',
url: "CS.aspx/Save",
data: '{files:' + JSON.stringify(files) + ',name:"' + name + '"}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (r) {
alert(r.d);
},
error: function (r) {
alert(r.responseText);
}
})
return false;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="file" name="fuUpload" id="fuUpload" multiple="multiple" />
<input name="txtName" type="text" id="txtName" />
<input type="submit" name="btnSave" value="Save" id="btnSave" />
</div>
</form>
</body>
</html>
<System.Web.Services.WebMethod> _
Public Shared Sub Save(files As List(Of FileDetails), name As String)
For i As Integer = 0 To files.Count - 1
Dim stream As New FileStream(files(i).Path, FileMode.Open)
Dim fileStream = New FileStream(HttpContext.Current.Server.MapPath("~/Files/" + files(i).Name), FileMode.Create, FileAccess.Write)
stream.CopyTo(fileStream)
fileStream.Dispose()
SaveDetails(name, HttpContext.Current.Server.MapPath("~/Files/" + files(i).Name), files(i).Name)
Next
End Sub
Private Shared Sub SaveDetails(name As String, filePath As String, fileName As String)
Dim str As String = ConfigurationManager.ConnectionStrings("conn").ConnectionString
Using con As New SqlConnection(str)
con.Open()
Using cmd As New SqlCommand("Insert INTO Files (Name,FilePath,FileName) values (@Name,@FilePath,@FileName)", con)
cmd.Parameters.AddWithValue("@Name", name)
cmd.Parameters.AddWithValue("@FilePath", filePath)
cmd.Parameters.AddWithValue("@FileName", fileName)
cmd.ExecuteNonQuery()
End Using
con.Close()
End Using
End Sub
Public Class FileDetails
Public Property Name() As String
Get
Return m_Name
End Get
Set
m_Name = Value
End Set
End Property
Private m_Name As String
Public Property Path() As String
Get
Return m_Path
End Get
Set
m_Path = Value
End Set
End Property
Private m_Path As String
End Class