Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8278567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:03:50+00:00 2026-06-08T09:03:50+00:00

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

  • 0

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);
    }
 });

 };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:03:52+00:00Added an answer on June 8, 2026 at 9:03 am

    Depending on the browser The html file control does not store the full path to the file. If you use Chrome and debug the script

    var iFile = iContainer.find( '#Ids2' ).val(); 
    

    Will return something like C:\fakepath\yourfile.txt. where as with IE the full path is returned.

    Also you in your Ajax you are not pushing the bytes of the file but only the filename which means unless you are going to only ever run this website in a browser on the webserver the chances of the file being in the same place as the webserver is slim.

    If you are trying to upload a file via ajax to a MVC controller I would suggest uploadify.

                $("#Ids2").uploadify(
                {
                    uploader: '/AttController/Attach',
                    swf: 'your/path/to/uploadify.swf',
                    cancelImg: 'your/path/to/cancel.jpg',
                    buttonText: 'Select File',
                    fileSizeLimit: '300KB',
                    fileTypeDesc: 'Image Files',
                    fileTypeExts: '*.gif; *.jpg; *.png',
                    auto: 'true',
                    multiple: 'false',
                    onError: function(type, info) {
    
                    },
                    onUploadSuccess: function(file, data, response) {
    
                    }
                });
    

    Then just change your controller action to

    public virtual ActionResult Upload(HttpPostedFileBase FileData)
    

    The FileData would have things like the FileName and would also have the file in an input stream.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to open or view an attachment(not save!) that a user uploaded
I'm trying to save the e-mail body and its attachments from javascript using a
I'm trying to save my Photo class that has a byte[] File field. When
I'm trying to save a huge NSArray to a file and then retrieve it...
I'm trying to use OpenURI to download a file from S3, and then save
I am trying to open the file in browser (browser will give me Open/Save
im trying to save a row in my settings table, it works all fine
Im trying to save a simple script in netbeans to htdocs, but i only
When trying to save the database using boost serialization, I encounter the segfault that
I'm trying to save some data into an array but unfortunately all the data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.