Access denied error while writing a file to the file system - myfileupload.saveas() throws system.unauthorizedexception

hi,
as part of my requirement , i have to perform read and  write  operations of  few files [ using the file upload control in my custom visual web part] and on submit button click.
but while writing these files - with the help of  fileupload control - and when i use  myfileupload.saveas(mylocation);
- i am saving these files into my D:\ drive of my server , where i am executing my code -, am getting access denied error.
it throws system.unauthorizedexception.
i have given full control on that folder where i was trying to store my attached files. and also  after following asp.net forums,
i have added  iusr group added and performed all those steps such that, the file is saved in my D:\ drive.
but unfortunately  that didnt happen.
also
a) i am trying the code with runwithelevatedprivileges(delegate() )  code
b) shared the drive within the  d :drive where i want o save the files.
c) given the full privieleges for the app pool identity- in my case , its
network service.
the  other strange thing is that, the same code works perfectly in  other machine, where the same sp, vs 2012  etc were installed .
would like to know, any other changes/ steps i need to make it on this  server, where i am getting the  error.
help is  appreciated!

vishnuS1984 wrote:
Hi Friends,
I have gone through scores of examples and i am failing to understand the right thing to be done to copy a file from one directory to another. Here is my class...So let's see... C:\GetMe1 is a directory on your machine, right? And this is what you are doing with that directory:
public static void copyFiles(File src, File dest) throws IOException
// dest is a 'File' object but represents the C:\GetMe1 directory, right?
fout = new FileOutputStream (dest);If it's a directory, where in your code are you appending the source file name to the path, before trying to open an output stream on it? You're not.
BTW, this is awful:
catch (IOException e)
IOException wrapper = new IOException("copyFiles: Unable to copy file: " +
src.getAbsolutePath() + "to" + dest.getAbsolutePath()+".");
wrapper.initCause(e);
wrapper.setStackTrace(e.getStackTrace());
throw wrapper;
}1) You're hiding the original IOException and replacing it with your own? For what good purpose?
2) Even if you had a good reason to do that, this would be simpler and better:
throw new IOException("your custom message goes here", e);
rather than explicitly invokign initCause and setStackTrace. Yuck!

Similar Messages

  • Getting access denied error while importing file using input type="file"

    Hi All,
    I am using struts application wherein I need to import file for some purpose.I have used input type="file" for the same which goes like:
    <input type="file" id="uploadFile" name="uploadFile" size="50">
    I have the import button on which I have used onClick event to call javascript function submitValues() used to validate all the fields from the page which goes like:
    <input type="button" name="select" value="Import" class="CSSButton" onClick="javascript:submitValues();">
    The JS function then in turn submits the form and calls the action.The problem is sometimes even when the correct path is specified for the file to be imported results in access denied error.This error comes sometimes and other times it works fine.But when this error comes,I need to relogin into the application and then it works fine.I am using IE7 for this.
    Any idea why I am getting access denied error while importing? Has it got something to do with IE7 version or with the input type="file" which is being used here?
    Thanks for any help if anyone can provide.
    Edited by: passionateforjava on Mar 4, 2009 2:18 AM

    vishnuS1984 wrote:
    Hi Friends,
    I have gone through scores of examples and i am failing to understand the right thing to be done to copy a file from one directory to another. Here is my class...So let's see... C:\GetMe1 is a directory on your machine, right? And this is what you are doing with that directory:
    public static void copyFiles(File src, File dest) throws IOException
    // dest is a 'File' object but represents the C:\GetMe1 directory, right?
    fout = new FileOutputStream (dest);If it's a directory, where in your code are you appending the source file name to the path, before trying to open an output stream on it? You're not.
    BTW, this is awful:
    catch (IOException e)
    IOException wrapper = new IOException("copyFiles: Unable to copy file: " +
    src.getAbsolutePath() + "to" + dest.getAbsolutePath()+".");
    wrapper.initCause(e);
    wrapper.setStackTrace(e.getStackTrace());
    throw wrapper;
    }1) You're hiding the original IOException and replacing it with your own? For what good purpose?
    2) Even if you had a good reason to do that, this would be simpler and better:
    throw new IOException("your custom message goes here", e);
    rather than explicitly invokign initCause and setStackTrace. Yuck!

  • Access Denied Error while accessing "Site Settings Access requests and invitations"

    Hi,
    I am getting Access Denied Error while accessing "Site Settings > Access requests and invitations" in SharePoint  2013 online. Currently I am the owner of the site and have "FULL CONTROL" access. I am able to access using
    site collection account. So, what permission I have to give my regular account to access this page?
    Thanks, Pal

    Hello,
    Have you recently changed the Owners group of the site collection or removed the user from the original owners group? 
    The reason I am asking is when the Access requests and invitations list are created, the permissions are given only to the default owners group at the time that the Access Request list was created.  If this "regular account" is not part of that owners
    group, the user will receive access denied.  Site Collection Admins always have permissions for the Access Request List.
    A workaround for the Access Denied issue is listed in the KB article http://support.microsoft.com/kb/2911390/en-us.  By giving the correct group or user the permissions to this list, the users will not receive
    the Access Denied issue anymore.  
    Preferably, in order to grant the user the full permissions ( you will see features like resending invitations may still fail after implementing the above workaround) there is one other workaround that may be required depending on what the original issue
    was.  Below are additional steps to restore full functionality.
    1)Access the /_layouts/15/permsetup.aspx of the site collection, make sure the default Owners Group
    is set correctly.  (There is a group selected)
    2) Add user to that Owners Group.  (Issue may be resolved at this step if the site collection Owners
    Group was never changed, if not continue to next step.)
    3) Implement workaround on http://support.microsoft.com/kb/2911390/en-us, by adding that owners
    group as Full control on Access Request list Permissions.
    Let me know how this works out for you.
    - Shpendi Jashari

  • Timerjob Access denied error while opening web object

    Hi Team,
    I have created a timer job to get list information on the site. Everything is fine in the development(Stand alone server) . Got access denied error while running same timer job in QA server(one app and one WFE).
    Note: This timer job is globally deployed.
    Code snippet : 
    SPSite site1 = webApp.Sites[0];
    SPWeb web = site1.RootWeb;
    SPSecurity.RunWithElevatedPrivileges(delegate()
    using (SPSite site = new SPSite(site1.ID))
    using (SPWeb currWeb = site.OpenWeb(web.ID))                  // Got access denied error here.
    Additional information:
    Sharepoint timer service account : Domain\SP_Farm
    Site app pool account : Domain\SP_App.
    Both accounts have site collection administrative access on the site. Do i need to check access permissions on DB level also  this error ?
    Waiting for urgent reply..

    Hi,
    1. Please check the link below:
    Fixing Access Denied Errors With SharePoint 2010 Timer Jobs
    http://www.sharepointsecurity.com/sharepoint/sharepoint-security/fixing-access-denied-errors-with-sharepoint-2010-timer-jobs/
    2. Try to set RemoteAdministratorAccessDenied  to false using PowerShell
    Access denied when deploying a timer Job or activating a feature from SharePoint 2010 content web application
    https://support.microsoft.com/kb/2564009?wa=wsignin1.0
    3. Check your ULS log for detail error message.
    Best Regards
    Dennis Guo
    TechNet Community Support

  • There was an error while writing data back to the server: Failed to commit objects to server : Duplicate object name in the same folder.

    Post Author: dmface15
    CA Forum: Administration
    I am working in a new enviorment and i am trying to save a report to the Crystal Server via the CMC. I am uploading the report from the objects tab and attempting to save to a folder. The report has 1 static defined parameter and that's it. When i click submit to save the report i receive the following error message: "There was an error while writing data back to the server: Failed to commit objects to server : Duplicate object name in the same folder." There is not a anothe report within the folder with that name. What could be causing this error message and equally important, what is the solution.

    hte message you received about duplicate user probably means something hadn't fully updated yet. Once it did then it worked...
    Regards,
    Tim

  • When I try to install Itunes, I get this error: (translated from Norwegian) There was a network error while trying to read from the file: C: \ windows \ installer \ iTunes.msi I have tried many times to reinstall, but nothing helps, please help me.

    When I try to install Itunes, I get this error: (translated from Norwegian) There was a network error while trying to read from the file: C: \ windows \ installer \ iTunes.msi I have tried many times to reinstall, but nothing helps, please help me.

    (1) Download the Windows Installer CleanUp utility installer file (msicuu2.exe) from the following Major Geeks page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page):
    http://majorgeeks.com/download.php?det=4459
    (2) Doubleclick the msicuu2.exe file and follow the prompts to install the Windows Installer CleanUp utility. (If you're on a Windows Vista or Windows 7 system and you get a Code 800A0046 error message when doubleclicking the msicuu2.exe file, try instead right-clicking on the msicuu2.exe file and selecting "Run as administrator".)
    (3) In your Start menu click All Programs and then click Windows Install Clean Up. The Windows Installer CleanUp utility window appears, listing software that is currently installed on your computer.
    (4) In the list of programs that appears in CleanUp, select any iTunes entries and click "Remove", as per the following screenshot:
    (5) Quit out of CleanUp, restart the PC and try another iTunes install. Does it go through properly this time?

  • Access denied error while trying to install graphics drivers

    Hello,
    I have a new toshiba laptop P70-A. I have installed windows 7 and the pc was working excellent up until now. Noticed yesterday that the nvidia automated system failed to install the new update. When I tried to install the new driver manually, even from the
    device manager, I got the access denied message. 
    A day now wasted reading all the possible causes and solutions but with no luck. Read all the forums and all the posts, tried almost everything. Below youll find everything I tried as a solution and failed.
    1.Disabled UAC
    2.Enabled the administrator account and trying to take control from there
    3.Run the subinacl and the reset.cmd
    4.Tried manually to take control the folder windows (and access denied while changing the rights)
    5. Scanned the system with everything there is available ( Kaspersky, MalwareBytes, RegCurePro, Tuneup Utilities, CCleaner) The system came out clean.
    6. Tried restoring the system to an earlier time (got again access denied error code 0x80070005)
    7. Checked all the group policies (all seem to be fine)
    8. Run a script to take immediate ownership over all of C:
    TAKEOWN /A /F C:
    then the next one
    TAKEOWN /F C: 
    9. With subinacl I run all the above scripts... (still nothing changed)
    @echo off
    title Resetting ACLs...
    echo.
    echo Determine whether we are on an 32 or 64 bit machine
    echo.
    if "%PROCESSOR_ARCHITECTURE%"=="x86" if "%PROCESSOR_ARCHITEW6432%"=="" goto x86
    set ProgramFilesPath=%ProgramFiles(x86)%
    goto startResetting
    :x86
    set ProgramFilesPath=%ProgramFiles%
    :startResetting
    echo.
    cd /d "%ProgramFilesPath%\Windows Resource Kits\Tools"
    echo. 
    echo Resetting ACLs...
    echo (this may take several minutes to complete)
    echo. 
    echo IMPORTANT NOTE: For this script to run correctly, you must change
    echo the values named Athena to be the Windows user account that
    echo you are logged in with.
    echo.
    echo ==========================================================================
    echo. 
    echo. 
    subinacl /subkeyreg HKEY_CURRENT_USER /grant=administrators=f /grant=system=f /grant=restricted=r /grant=Athena=f /setowner=administrators > %temp%\subinacl_output.txt
    echo. 
    echo. 
    subinacl /keyreg HKEY_CURRENT_USER /grant=administrators=f /grant=system=f /grant=restricted=r /grant=Athena=f /setowner=administrators >> %temp%\subinacl_output.txt
    echo. 
    echo. 
    subinacl /subkeyreg HKEY_LOCAL_MACHINE /grant=administrators=f /grant=system=f /grant=users=r /grant=everyone=r /grant=restricted=r /setowner=administrators >> %temp%\subinacl_output.txt
    echo. 
    echo. 
    subinacl /keyreg HKEY_LOCAL_MACHINE /grant=administrators=f /grant=system=f /grant=users=r /grant=everyone=r /grant=restricted=r /setowner=administrators >> %temp%\subinacl_output.txt
    echo. 
    echo. 
    subinacl /subkeyreg HKEY_CLASSES_ROOT /grant=administrators=f /grant=system=f /grant=users=r /setowner=administrators >> %temp%\subinacl_output.txt
    echo. 
    echo. 
    subinacl /keyreg HKEY_CLASSES_ROOT /grant=administrators=f /grant=system=f /grant=users=r /setowner=administrators >> %temp%\subinacl_output.txt
    echo. 
    echo. 
    echo System Drive...
    subinacl /subdirectories %ProgramFilesPath%\ /grant=administrators=f /grant=system=f /grant=users=e >> %temp%\subinacl_output.txt
    echo. 
    echo. 
    echo Windows Directory...
    subinacl /subdirectories %windir%\ /grant=administrators=f /grant=system=f /grant=users=e >> %temp%\subinacl_output.txt
    echo. 
    echo. 
    echo ==========================================================================
    echo. 
    echo FINISHED.
    echo. 
    echo Press any key to exit . . .
    pause >NUL
    Im frustrated really... ANY help at all would be really appreciated.
    Thanks in Advance and sorry for the long post
    Athena 

    Hello,
    Thanks for the replies, i much appreciate it. I tried all of the above with no luck again. Safe mode allows me though to install drivers but thats reverting the moment im entering windows. Im always running commands and programs as a administrator or in
    the Admin enabled account.
    It seems the problem is solved today. Via tune up utilities I disabled most of the startup programs and services and it seems that 1 service is causing this issue. Although I havent played much with the disabled services but 3 remain to be checked. One of
    the three is causing this.
    Thanks again guys and Ill keep you posted about the soft. conflict.
    Athena

  • Access denied Error while calling Web Service form Infopath Form 2010.

    Hi Dear All,
    I have been facing an error while calling an GetUserProfileByName() web service method from InfoPath 2010 from.
    i have FBA(Forms Base Authentication )configured . After Infopath form published to site collection when i select an user from people picker control i want to get Email Id of Selected user for that i am calling getUserProfileByName() Web Method, but 
    i am getting Access denied error code 500.
    Any Help would be more than welcome.
    Thanks.

    Hi,
    Greetings. Please check 
    Check the IE settings. Click Internet Options> Security>Custom level. Make sure that the ‘Access data source across domains’ is enabled. Make sure that you have permission to the web service and to the content which the web service tries to modify.
    For more information, please refer to this site:
    "Access is denied." error in Infopath 2007 form + ASMX: http://us.generation-nt.com/answer/access-denied-error-infopath-2007-form-plus-asmx-help-65808252.html
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • Access denied error while exporting chart to excel

    I need to export data from a gridview to chart in excel. Through system account credentials it works fine. But through a user's credentials its giving an access denied error. The gridview data is exported properly but the current chart which is displayed
    on page is not getting displayed in excel.
    So is there any other way to achieve this?
    I was thinking og saving it to virtual folder in the Site but I cannot figure out the exact code for it. Since file upload control is not involved, how to save the chart to the virtual folder. Any inputs on this?

    Hello,
    Would you mind if you use "runwithelevatedprivileges" in your code to execute code with admin privilege?
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx
    >I was thinking og saving it to virtual folder in the Site
    Do you want to save excel in system folder or SP site folder?
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Access denied error while uploading the document into document library which is associated with a content type

    hi,
     am trying to upload a document in a document library which is associated  with content types [ the content type contains 10 site columns and one of them is taxonomy field]. i added this content type in the document library.
    this document library is residing in a team site which is saved as a template and  based on this template i have created sub sites.
    and when i tried to upload a file to the doc lib, it throws me "access denied error".
    what may be went wrong .
    any help is  appreciated!

    Access denied indicates the user account uploading the file doesn't have access to the library, or sometimes it means there's already a document in the library with the same name that was never checked in. It's also possible that your template contains
    custom code that tries to do something that is not allowed.
    Kind regards,
    Margriet Bruggeman
    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

  • "general access denied error" while implementing out-of-process COM Server Implementation in Windows Phone 8.1

    I have a Service (.exe) where I was registering for my COM Component like below
    CoInitializeEx(NULL, COINIT_MULTITHREADED);
    HRESULT hres = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, 0);
    if (hres != S_OK)
    OutputDebugStringA("Security Descriptor not initialized");
    ITypeLib* pTypeLib;
    HRESULT hr_1 = LoadTypeLibEx(L"ServiceIdl.tlb", REGKIND_REGISTER, &pTypeLib);
    if (pTypeLib != NULL)
    pTypeLib->Release();
    RegisterServer(L"Service.exe", CLSID_classAImpl, L"ClassAImpl Sample", L"Component.ClassAImpl", L"Component.ClassAImpl.1", 0);
    g_hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    DWORD reg = 0;
    IClassFactory *pIFactory = new classAFactory;
    HRESULT hr0 = CoRegisterClassObject(CLSID_classAImpl, pIFactory, CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &reg);
    if (FAILED(hr0))
    OutputDebugStringA("classAImpl is not registered");
    CoUninitialize();
    exit(1);
    HRESULT hr1 = CoResumeClassObjects();
    if (hr1 == S_OK)
    OutputDebugStringA("classAImpl is Resumed Registering");
    WaitForSingleObject(g_hEvent, INFINITE);
    CloseHandle(g_hEvent);
    CoRevokeClassObject(reg);
    pIFactory->Release();
    CoUninitialize();
    From Client Code I am CreatingInstance  Like Below
    COSERVERINFO si;
    MULTI_QI qi;
    COAUTHINFO cai = { RPC_C_AUTHN_NONE, RPC_C_AUTHZ_NONE, 0, RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IMPERSONATE, 0, EOAC_NONE };
    si.dwReserved1 = 0;
    si.pwszName = L"\\\\localhost";
    si.pAuthInfo = &cai;
    si.dwReserved2 = 0;
    qi.pIID = &IID_classA;
    qi.pItf = NULL;
    qi.hr = 1;
    CoInitializeEx(NULL, COINIT_MULTITHREADED);
    HRESULT hr = CoCreateInstanceEx(CLSID_classAImpl, 0, CLSCTX_LOCAL_SERVER, &si, 1, &qi);
    hr returning error "general access denied error";

    I think we may run into the limitations mentioned in the remarks of CoCreateInstanceFromApp doc(show as below). If you can provide a repro project, I
    can give you more details about what happens.
    The CoCreateInstanceFromApp function reads class registrations only from Fusion contexts and manifests, and from the HKLM\SOFTWARE\Classes\CLSID registry hive.
    Only built-in classes that are supported in the app container are supplied. Attempts to activate unsupported classes, including all classes installed by 3rd-party code as well as many Windows classes, result in error code
    REGDB_E_CLASSNOTREG.
    The CoCreateInstanceFromApp function is available to Windows Store apps. Desktop applications can call this function, but they have the same restrictions as Windows Store apps.
    If you are trying to call some windows classes in your library, I will suggest you check how to create windows runtime out of process component by viewing
    this sample. This is what I usually do.
    To be honest, I did not try to implement the out of process COM component using the method you tried as we previsouly do on desktop. I will suggest you try to register a very simple library(like a signle class and single interface which returns an integer),
    and see if it will work.
    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

  • Two forests trusted "Access denied error" while RDP

    Hi Everybody,
    I have two forests 
    for ex:
    TestA & TestB
    I have created one Global group called "XYZ" in 'TestA' forest and added the users. 
    Both the forests are trusted. 
    In 'TestB' forest i have two servers. Computer1 & Computer2
    I have added "XYZ" group from "TestA" to Local administrators group of "TestB" and these groups are in restricted groups.
    Iam able to access upn \\computer1\C$ from TestA forest. But when i am trying to RDP to "Computer1" iam getting Access Denied error.
    Computer1 is (2008 R2) and forest & domain functional lever is 2003
    Kindly advise on this issue.
    Thanks!!

    Hi,
    I assume you don't have RDSH role installed.
    Have a look here
    This post is provided AS IS with no warranties or guarantees, and confers no rights.
    ~~~
    Questo post non fornisce garanzie e non conferisce diritti

  • Access Denied error when trying to print over the network

    I just upgraded my Internet service and leased a new modem. My laptop is connected to the network and is able to browse the Internet. I have file and printer shared tuned on on both the desktop and the laptop. The printer is listed on my laptop, but I cannot print over the network to my HP PSC 1401 All In One. I get an Access Denied error even though the printer should still be connected to the network.

    bump

  • Access denied error --  while copying file to a specific directory

    Hi Friends,
    I have gone through scores of examples and i am failing to understand the right thing to be done to copy a file from one directory to another. Here is my class
    package ZipTest;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    public class TestCopy {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              File source = new File("C:\\mkyong\\test_1.txt");
              File desc = new File("C:\\GetMe1");
              try {
                   copyFiles(source,desc);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         public static void copyFiles(File src, File dest) throws IOException
         if (!src.exists())
         throw new IOException("copyFiles: Can not find source: " + src.getAbsolutePath()+".");
         else if (!src.canRead())
         throw new IOException("copyFiles: No right to source: " + src.getAbsolutePath()+".");
         if (src.isDirectory())
         if (!dest.exists())
         if (!dest.mkdirs())
         throw new IOException("copyFiles: Could not create direcotry: " + dest.getAbsolutePath() + ".");
         String list[] = src.list();
         for (int i = 0; i < list.length; i++)
         File dest1 = new File(dest, list);
         File src1 = new File(src, list[i]);
         copyFiles(src1 , dest1);
         else
         FileInputStream fin = null;
         FileOutputStream fout = null;
         byte[] buffer = new byte[4096];
         int bytesRead;
         try
         fin = new FileInputStream(src);
         fout = new FileOutputStream (dest);
         while ((bytesRead = fin.read(buffer)) >= 0)
         fout.write(buffer,0,bytesRead);
         catch (IOException e)
         IOException wrapper = new IOException("copyFiles: Unable to copy file: " +
         src.getAbsolutePath() + "to" + dest.getAbsolutePath()+".");
         wrapper.initCause(e);
         wrapper.setStackTrace(e.getStackTrace());
         throw wrapper;
         finally
         if (fin != null) { fin.close(); }
         if (fout != null) { fin.close(); }
    But i am getting the following errorjava.io.IOException: copyFiles: Unable to copy file: C:\mkyong\test_1.txttoC:\GetMe1.
         at java.io.FileOutputStream.open(Native Method)
         at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
         at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
         at ZipTest.TestCopy.copyFiles(TestCopy.java:68)
         at ZipTest.TestCopy.main(TestCopy.java:18)
    Caused by: java.io.FileNotFoundException: C:\GetMe1 (Access is denied)
         ... 5 more
    It would be really helpful to have your guidance.
    Thanks & Regards
    VS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    vishnuS1984 wrote:
    Hi Friends,
    I have gone through scores of examples and i am failing to understand the right thing to be done to copy a file from one directory to another. Here is my class...So let's see... C:\GetMe1 is a directory on your machine, right? And this is what you are doing with that directory:
    public static void copyFiles(File src, File dest) throws IOException
    // dest is a 'File' object but represents the C:\GetMe1 directory, right?
    fout = new FileOutputStream (dest);If it's a directory, where in your code are you appending the source file name to the path, before trying to open an output stream on it? You're not.
    BTW, this is awful:
    catch (IOException e)
    IOException wrapper = new IOException("copyFiles: Unable to copy file: " +
    src.getAbsolutePath() + "to" + dest.getAbsolutePath()+".");
    wrapper.initCause(e);
    wrapper.setStackTrace(e.getStackTrace());
    throw wrapper;
    }1) You're hiding the original IOException and replacing it with your own? For what good purpose?
    2) Even if you had a good reason to do that, this would be simpler and better:
    throw new IOException("your custom message goes here", e);
    rather than explicitly invokign initCause and setStackTrace. Yuck!

  • Access Denied error while reading from filestream

    Hi Everyone.
    I have an intranet application that stores files in SQL filestream.
    On my dev machine, everything works like a charm.
    I'm able to upload and store files into SQL filestream (AjaxUpload) and able to downlaod them.
    On the live server, I'm able to upload files, delete them, but when I try to download the file from filestream, I get the following error:
    Access is denied
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.ComponentModel.Win32Exception: Access is denied
    Source Error:
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    Stack Trace:
    [Win32Exception (0x80004005): Access is denied]
    System.Data.SqlTypes.SqlFileStream.OpenSqlFileStream(String path, Byte[] transactionContext, FileAccess access, FileOptions options, Int64 allocationSize) +1465594
    System.Data.SqlTypes.SqlFileStream..ctor(String path, Byte[] transactionContext, FileAccess access, FileOptions options, Int64 allocationSize) +398
    System.Data.SqlTypes.SqlFileStream..ctor(String path, Byte[] transactionContext, FileAccess access) +27
    quotes_GetFileStream.quotes_GetFileStream_Load(Object sender, EventArgs e) +740
    System.Web.UI.Control.LoadRecursive() +71
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3048
    The application pool is set to integrated, V.4.0,  and I use a domain user for the identity authentication back to SQL.
    I gave that user DB_Owner rights to the SQL Database for that application.
    Even tried giving it all the SQL Server Roles, though i still get the above error.
    When I change the Identity username to mine (I have Domain Admin rights), everything works flawlessly on the live server.
    What rights am I missing to give that user so he can read from SQL filestream properly.
    Here is the block of code that gets the file from filestream and pushes it to the browser, maybe I'm missing something here (though once i modify the user it works great).
    Dim RecId As Integer = -1
    If Not IsNothing(Request.QueryString("ID")) And IsNumeric(Request.QueryString("ID")) Then
    RecId = CType(Request.QueryString("ID"), Integer)
    End If
    Dim ConString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ToString
    Using Con As SqlConnection = New SqlConnection(ConString)
    Con.Open()
    Dim txn As SqlTransaction = Con.BeginTransaction()
    Dim Sql As String = "SELECT FileData.PathName() , GET_FILESTREAM_TRANSACTION_CONTEXT() as TransactionContext, [FileName], [FileExtension] FROM [QAttach] where RecId = @RecId"
    Dim cmd As SqlCommand = New SqlCommand(Sql, Con, txn)
    cmd.Parameters.Add("@RecID", Data.SqlDbType.Int).Value = RecId
    Dim Rdr As SqlDataReader = cmd.ExecuteReader()
    While Rdr.Read()
    Dim FilePath As String = Rdr(0).ToString()
    Dim objContext As Byte() = DirectCast(Rdr(1), Byte())
    Dim fname As String = Rdr(2).ToString()
    Dim FileExtension As String = Rdr(3).ToString()
    Dim sfs As SqlFileStream = New SqlFileStream(FilePath, objContext, FileAccess.Read)
    Dim Buffer As Byte() = New Byte(CInt(sfs.Length) - 1) {}
    sfs.Read(Buffer, 0, Convert.ToInt32(Buffer.Length))
    Response.Buffer = True
    Response.Charset = ""
    Response.Cache.SetCacheability(HttpCacheability.NoCache)
    Response.ContentType = FileExtension
    Response.AddHeader("content-disposition", "attachment;filename=" & fname)
    Response.BinaryWrite(Buffer)
    Response.Flush()
    Response.End()
    sfs.Close()
    End While
    End Using
    Thanks.
    Oren

    @William Bosacker:
    Please accept our apologies for any mistreatment.  While there's certainly no legal recourse for posts on an open forum like this, we do take steps to try to keep the forums a pleasant and friendly place to visit, and toward this end, two other moderators
    have already cleaned the thread and have begun to address the abuse.
    Not to defend the manner in which it was addressed, I must still point out that necro posting to a thread (this thread is from late 2013) and proposing your post as an answer are both generally discouraged. Again, I cannot condone the way in which it was
    presented, but I can understand why the other contributors thought something should be said.
    The recommended way to contribute information like this would be to create a new Discussion thread with content something like:
    "I was experiencing XYZ issue and while searching for a resolution I found this thread [link to old thread].  But after trying A, B, and C, I found that the following actually resolved my problem [code snippet].  I thought this might be helpful
    for anyone else with this issue... yada yada"
    In the case of this original thread, the issue was most certainly permission related.  While the underlying network permissions would certainly need to allow that user to access the server, the root problem may well have been within the SQL table permissions
    themselves.  The OP of the original thread really didn't provide enough context to know if they had the internal database permissions set correctly.
    The information you've provided essentially shows one way to set the table permissions, but it isn't necessarily the only way.  Its also possible that the issue could be resolved by modifying permission entries within the SQL manager rather than through
    a particular script file.  So while this information may indeed be helpful to someone in the future, it does not necessarily answer the question of this thread.  Only the OP has enough information to know if this can be applied to their situation;
    and since the thread is several years old and was originally closed by a moderator, there is very little chance that the OP will be back to respond.
    Hopefully this clears the air a little and will allow us all to get back to trying to help the VB development community within the guidelines of the forum.
    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

Maybe you are looking for

  • How do you clone a hard drive with boot camp?

    My daughter got a new 13" Macbook pro in July.  She is still running Lion.  Se started to exerience system freezes.  She called Applye support which had her reset the PRAM(?).  The the system would no longer boot.  When she went away to college, I se

  • Need to create PCL that doesn't reference the resident device fonts

    Greetings SAP folks, JSYK where I'm coming from on this...I am a print/data stream guy.  I know little about the workings of SAP.  The workflow of the customer is......SAPscript to PCL to IBM's AFP (Advanced Function Presentation) to IBM IPDS (Intell

  • Unable to print the document thru Crystal Integration

    Hi All, Could anybody help me on the issue given below. One of our client Issue while printing from crystal Integration in SAP Business One. I can able to view the crystal report through Crystal Integration but i am unable to print the document.No Er

  • Reading Advance Queuing with XMLType payload and JDBC Driver character encoding

    Hi I've got a problem retrieving the message from the queue with XMLType payload in Java. It was working fine in 10g database but after the switch to 11g it returns corrupted string instead of real XML message. Database NLS_LANG setting is AL32UTF8 I

  • Order of sections in a PE file.

    Hi, I have been studying PE file format from last few days. One thing that I observed while studying the section tables is that, for all the PEs that I studied .text section is the first section. I created few more PEs but they also had text section