Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 783 characters in body
Source Link
ZVenue
  • 5k
  • 17
  • 63
  • 94

I am trying to save attachments in ravenDb. I am getting a file not found error.

MVC View:

 <input type="file" name="file" id="Ids2" style="float:right"/> 

Over an ajax call, I am passing the value of the file name selected in the above control to the controller method - which in turns sends the file name to a custom method called "Upload"

public virtual string Upload(string fileName) { IDocumentSession session = GetCurrentDocumentSession(); var id = "upload/" + randomGen(); session.Advanced.DatabaseCommands.PutAttachment(id,null, File.ReadAllBytes(fileName), optionalMetaData); return id; } 

I am getting C:\ProgramFiles (x86)....does not have the file specified. Lets say in the view - I browsed to C:/Doc1.txt and clicked on Add button that saves bunch of other fields on the view and also picks up the file name/path from the file upload control.

I get an error at session.advance.databasecommands... line

Could not find file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\Doc1.txt'.

If I manually move the Doc1.txt file to the above location, ravenDB saves the attachment and I can see it from localhost:8080/static/upload/keyvalue

How can I make ravenDB take the file from the location the user selects and not from the what it looks like a default location of c:programfiles.....

EDIT:

 function () { var iFile = iContainer.find( '#Ids2' ).val(); var DataToSave = { 'Attachment' : iFile }; var encodedData = $.toJSON(DataToSave); $.ajax({ type: 'POST' , url: '/AttController/Attach' , data: encodedData, contentType: 'application/json; charset=utf-8' , success: function (rc) { if (rc.Success) { // more javascript reroutes..business logic } else { alert(rc.Message); } }, error: function (xhr, ajaxOptions, thrownError) { alert( 'Error attaching \n' + xhr.response); } }); }; 

I am trying to save attachments in ravenDb. I am getting a file not found error.

MVC View:

 <input type="file" name="file" id="Ids2" style="float:right"/> 

Over an ajax call, I am passing the value of the file name selected in the above control to the controller method - which in turns sends the file name to a custom method called "Upload"

public virtual string Upload(string fileName) { IDocumentSession session = GetCurrentDocumentSession(); var id = "upload/" + randomGen(); session.Advanced.DatabaseCommands.PutAttachment(id,null, File.ReadAllBytes(fileName), optionalMetaData); return id; } 

I am getting C:\ProgramFiles (x86)....does not have the file specified. Lets say in the view - I browsed to C:/Doc1.txt and clicked on Add button that saves bunch of other fields on the view and also picks up the file name/path from the file upload control.

I get an error at session.advance.databasecommands... line

Could not find file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\Doc1.txt'.

If I manually move the Doc1.txt file to the above location, ravenDB saves the attachment and I can see it from localhost:8080/static/upload/keyvalue

How can I make ravenDB take the file from the location the user selects and not from the what it looks like a default location of c:programfiles.....

I am trying to save attachments in ravenDb. I am getting a file not found error.

MVC View:

 <input type="file" name="file" id="Ids2" style="float:right"/> 

Over an ajax call, I am passing the value of the file name selected in the above control to the controller method - which in turns sends the file name to a custom method called "Upload"

public virtual string Upload(string fileName) { IDocumentSession session = GetCurrentDocumentSession(); var id = "upload/" + randomGen(); session.Advanced.DatabaseCommands.PutAttachment(id,null, File.ReadAllBytes(fileName), optionalMetaData); return id; } 

I am getting C:\ProgramFiles (x86)....does not have the file specified. Lets say in the view - I browsed to C:/Doc1.txt and clicked on Add button that saves bunch of other fields on the view and also picks up the file name/path from the file upload control.

I get an error at session.advance.databasecommands... line

Could not find file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\Doc1.txt'.

If I manually move the Doc1.txt file to the above location, ravenDB saves the attachment and I can see it from localhost:8080/static/upload/keyvalue

How can I make ravenDB take the file from the location the user selects and not from the what it looks like a default location of c:programfiles.....

EDIT:

 function () { var iFile = iContainer.find( '#Ids2' ).val(); var DataToSave = { 'Attachment' : iFile }; var encodedData = $.toJSON(DataToSave); $.ajax({ type: 'POST' , url: '/AttController/Attach' , data: encodedData, contentType: 'application/json; charset=utf-8' , success: function (rc) { if (rc.Success) { // more javascript reroutes..business logic } else { alert(rc.Message); } }, error: function (xhr, ajaxOptions, thrownError) { alert( 'Error attaching \n' + xhr.response); } }); }; 
edited tags
Link
ZVenue
  • 5k
  • 17
  • 63
  • 94
edited tags
Link
ZVenue
  • 5k
  • 17
  • 63
  • 94
Source Link
ZVenue
  • 5k
  • 17
  • 63
  • 94
Loading